script模塊可以在本地寫一個腳本,然后在遠程服務器上執行。如下
name: 將本地腳本復制到遠程主機并運行之
action: script
creates # 一個文件名,當這個文件存在,則該命令不執行
free_form= # 本地腳本路徑
removes # 一個文件名,這個文件不存在,則該命令不執行
案例:在遠程主機上執行腳本(本地腳本不需要賦執行權限)
~~~
[admin@node1 tmp]$ ansible webserver -m script -a 'a.sh' -b --ask-sudo-pass
[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature will be removed in version 2.6. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
SUDO password:
192.168.20.137 | SUCCESS => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.20.137 closed.\r\n",
"stdout": "\r\n",
"stdout_lines": [
""
]
}
192.168.20.138 | SUCCESS => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.20.138 closed.\r\n",
"stdout": "\r\n",
"stdout_lines": [
""
]
}
[admin@node1 tmp]$ ansible webserver -a 'cat /tmp/a.txt' -b --ask-sudo-pass
[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature will be removed in version 2.6. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
SUDO password:
192.168.20.138 | SUCCESS | rc=0 >>
Sat Mar 17 16:38:27 CST 2018
192.168.20.137 | SUCCESS | rc=0 >>
Sat Mar 17 16:38:27 CST 2018
~~~
- 第一章:Ansible基礎入門
- 第二章:Ansible系列手冊
- 第一節:Ansible系列之主機清單
- 第二節:Ansible系列之變量
- 第三節:Ansible系列之YAML
- 第四節:Ansible系列之條件判斷
- 第五節:Ansible系列之循環
- 第六節: Ansible系列之tags
- 第七節:Ansible系列之Jinja2
- 第三章:Ansible系列之模塊
- 第一節:user模塊
- 第二節:group模塊
- 第三節:cron模塊
- 第四節:copy模塊
- 第五節: file模塊
- 第六節:yum模塊
- 第七節:service模塊
- 第八節:shell模塊
- 第九節:script模塊
- 第十節:setup模塊
- 第十一節:filesystem和mount模塊
- 第十二節:synchronize模塊
- 第十三節: get_url模塊
- 第十四節: package模塊
- 第十五節:stat模塊
- 第十六節:unarchive模塊
- 第十七節: commang模塊
- 第四章:Ansible-playbook介紹
- 第五章:Ansible系統環境
- 第一節:Ansible Role 系統環境之epel設置