在远程上执行本地脚本,而无需在Ansible中复制本地脚本 [英] Execute local script on remote without copying it across in Ansible

查看:892
本文介绍了在远程上执行本地脚本,而无需在Ansible中复制本地脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Ansible中的远程主机上执行本地脚本,而无需跨脚本复制然后执行它?

Is it possible to execute a local script on a remote host in Ansible without copying it across and then executing it?

脚本,shell和命令模块似乎都可能是答案,但我不确定哪个是最好的.

The script, shell and command modules all seems like they might be the answer but I'm not sure which is best.

脚本模块将自身描述为在传输后在远程节点上运行本地脚本",但是给出的示例并不建议进行复制操作-例如,没有src,dest-所以也许这就是答案?

The script module describes itself as "Runs a local script on a remote node after transferring it" but the examples given don't suggest a copy operation - e.g. no src, dest - so maybe this is the answer?

推荐答案

脚本模块FTW

任务:

- name: Ensure docker repo is added
  script: "{{ role_path }}/files/add-docker-repo.sh"
  register: dockeraddrepo
  notify: Done dockeraddrepo
  when: ansible_local.dockeraddrepo | d(0) == 0

处理程序:

- name: Done dockeraddrepo
  copy:
    content: '{{ dockeraddrepo }}'
    dest: /etc/ansible/facts.d/dockeraddrepo.fact

这篇关于在远程上执行本地脚本,而无需在Ansible中复制本地脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆