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

查看:32
本文介绍了在远程执行本地脚本而不在 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天全站免登陆