chdir=/目录 进入到指定目录
creates 文件存在 脚本不执行
removes 文件存在 脚本执行
1.执行script模块
[root@ansible ~]# cat /root/test.sh
#!/bin/sh
echo `hostname`
[root@ansible ~]# ansible mysql -m script -a '/root/test.sh'
192.168.56.88 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.56.88 closed./r/n",
"stderr_lines": [
"Shared connection to 192.168.56.88 closed."
],
"stdout": "mysql8/r/n",
"stdout_lines": [
"mysql8"
]
}
2.可以针对某个文件存在或者不存在来执行脚本,
/etc/passwd文件存在,所以后面的语句被跳过
[root@ansible ~]# ansible mysql -m script -a 'creates=/etc/passwd chdir=/root test.sh'
192.168.56.88 | SKIPPED
/etc/passwd文件存在,所以后面的语句被执行
[root@ansible ~]# ansible mysql -m script -a 'removes=/etc/passwd chdir=/root test.sh'
192.168.56.88 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.56.88 closed./r/n",
"stderr_lines": [
"Shared connection to 192.168.56.88 closed."
],
"stdout": "mysql8/r/n",
"stdout_lines": [
"mysql8"
]
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
ansible
- 上一篇:ansible模块--groups模块
- 下一篇:ansible模块--copy模块