企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
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 ~~~