ansible(5)--ansible的script模块
1. script模块
-
作用:在远程主机运行本地的脚本;
-
调用格式:
-m script -a "/PATH/TO/SCRIPT_FILE";
-
参数:
creates
:如果其后跟的文件存在,则不执行脚本;removes
:如果其后跟的文件存在,则执行脚本; -
示例:在
Ansible
主机上编写脚本,然后推送至被控端运行;[root@xuzhichao ~]# cat file1.sh #!/bin/bash cat /etc/passwd | awk -F: '{print $1,$2}' [root@xuzhichao ~]# ansible 192.168.20.22 -m script -a 'removes=/etc/passwd /root/file1.sh' 192.168.20.22 | CHANGED => { "changed": true, "rc": 0, "stderr": "Shared connection to 192.168.20.22 closed.\r\n", "stderr_lines": [ "Shared connection to 192.168.20.22 closed." ], "stdout": "root x\r\nbin x\r\ndaemon x\r\nadm x\r\nlp x\r\nsync x\r\nshutdown x\r\nhalt x\r\nmail x\r\noperator x\r\ngames x\r\nftp x\r\nnobody x\r\nsystemd-network x\r\ndbus x\r\npolkitd x\r\nsshd x\r\npostfix x\r\nchrony x\r\nxu x\r\nwang x\r\nwang1 x\r\nwang3 x\r\nwang4 x\r\nwang5 x\r\nzabbix x\r\nxu2 x\r\ntcpdump x\r\ndhcpd x\r\nrpc x\r\nrpcuser x\r\nnfsnobody x\r\nwww x\r\ntss x\r\nnginx x\r\nsaslauth x\r\nnscd x\r\nnslcd x\r\nxu1 x\r\nxu10 x\r\n", "stdout_lines": [ "root x", "bin x", "daemon x", "adm x", "lp x", "sync x", "shutdown x", "halt x", "mail x", "operator x", "games x", "ftp x", "nobody x", "systemd-network x", "dbus x", ] }