ansible-playbook 执行脚本传递参数

1840人浏览 / 0人评论

执行命令服务器配置:

---
- hosts: s2
  vars:
    key: "123123"
  tasks:
    - name: "demo shell"
      shell: sh /tmp/test1.sh  {{key}}

远程服务器脚本:

echo helloworld I love ansible $1> /tmp/test1.log

执行命令:

ansible-playbook test1.yml

外部传递参数命令

ansible-playbook test1.yml -e "key=手动阀说"

异步执行

---
- hosts: s2
  tasks:
    - name: "demo shell"
      shell: sh /tmp/test1.sh  {{key}}
      async: 180  ##超时时间
      poll: 10    ##轮询间隔

 

 

参考:https://www.liangzl.com/get-article-detail-17671.html

http://www.ansible.com.cn/docs/playbooks_loops.html#standard-loops

全部评论