Ansible

Linux_309_Ansible模块之script执行脚本

2022-11-16  本文已影响0人  为宇绸缪

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模块,可以批量让所有被管理的机器执行脚本,且该脚本不需要在客户端上存在

上一篇 下一篇

猜你喜欢

热点阅读