script模块
功能:把管理机器上的脚本远程的传输到被管理节点上去执行
比起shell模块,script模块功能更强大,在管理机器本地有一份脚本,就可以在所有被管理机器上去运行
script模块参数
creates
removes
chdir
查看帮助信息 ansible-doc -s script
应用案例
1、在管理节点上创建脚本
mkdir /myscripts
echo -e "pwd\nhostname" > /myscripts/local_hostname.sh
2、授权
chmod +x /myscripts/local_hostname.sh
远程的批量执行脚本,且在客户端上不需要存在该脚本
ansible yu -m script -a "/myscripts/local_hostname.sh"
[root@yuweijie /]# ansible yu -m script -a "/myscripts/local_hostname.sh"
192.168.178.122 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.178.122 closed.\r\n",
"stderr_lines": [
"Shared connection to 192.168.178.122 closed."
],
"stdout": "/root\r\nrsync\r\n",
"stdout_lines": [
"/root",
"rsync"
]
}
192.168.178.121 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.178.121 closed.\r\n",
"stderr_lines": [
"Shared connection to 192.168.178.121 closed."
],
"stdout": "/root\r\nnfs_machine\r\n",
"stdout_lines": [
"/root",
"nfs_machine"
]
}
利用script模块,可以批量让所有被管理的机器执行脚本,且该脚本不需要在客户端上存在
网友评论