ansile(2)模块之script
ansible script模块用来为远端目标主机运行管理机(本地)的脚本参数是否必须默认选项说明
createsno
当文件存在,这步不运行
free_formyes
运行参数
removesno
当文件不存在时,这步不允许
[*]运行脚本示例
1
2
3
4
5
# cat ckl.sh
#!/bin/bash
ps -ef | grep httpd | grep -v grep
date
echo "*******************"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# ansible webserver -m script -a "/root/ckl.sh"
172.16.110.48 | SUCCESS => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 172.16.110.48 closed.\r\n",
"stdout": "root 44242 10 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\napache 44243442420 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\napache 44244442420 22:30 ? 00:00:00
/usr/sbin/httpd -DFOREGROUND\r\napache 44245442420 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\napache 44246442420 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\napache 44247442420 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\nWed Dec 28 23:09:14 CST 2016\r\n*******************\r\n",
"stdout_lines": [
"root 44242 10 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"apache 44243442420 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"apache 44244442420 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"apache 44245442420 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"apache 44246442420 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"apache 44247442420 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"Wed Dec 28 23:09:14 CST 2016",
"*******************"
]
}
172.16.110.47 | SUCCESS => {
"changed": true,
"rc": 0,
1
2
3
4
5
6
7
8
9
10
11
12
13
"stderr": "Shared connection to 172.16.110.47 closed.\r\n",
"stdout": "root 44301 10 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\napache 44303443010 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\napache 44304443010 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\napache 44305443010 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\napache 44306443010 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\napache 44307443010 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND\r\nWed Dec 28 23:09:14 CST 2016\r\n*******************\r\n",
"stdout_lines": [
"root 44301 10 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"apache 44303443010 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"apache 44304443010 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"apache 44305443010 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"apache 44306443010 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"apache 44307443010 22:30 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND",
"Wed Dec 28 23:09:14 CST 2016",
"*******************"
]
}
2.添加参数的脚本
1
2
3
4
5
6
# cat ckl.sh
#!/bin/bash
ARG=$1
ps -ef | grep $1 | grep -v grep
date
echo "*******************"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# ansible webserver -m script -a "/root/ckl.sh sshd free_form=yes"
172.16.110.47 | SUCCESS => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 172.16.110.47 closed.\r\n",
"stdout": "root 1023 10 Dec27 ? 00:00:00 /usr/sbin/sshd\r\nroot 10338 10230 Dec27 ? 00:00:00 sshd: root@pts/0\r\nroot 46439 10230 23:15 ? 00:00:00 sshd: root@pts/1\r\nroot 46517464390 23:15 pts/1 00:00:00 /bin/sh -c/root/.ansible/tmp/ansible-tmp-1482938153.95-199337961978722/ckl.sh sshd free_form=yes && sleep 0\r\nroot 46529465170 23:15 pts/1 00:00:00 /bin/bash /root/.ansible/tmp/ansible-tmp-1482938153.95-199337961978722/ckl.sh sshd free_form=yes\r\nWed Dec 28 23:15:54 CST 2016\r\n*******************\r\n",
"stdout_lines": [
"root 1023 10 Dec27 ? 00:00:00 /usr/sbin/sshd",
"root 10338 10230 Dec27 ? 00:00:00 sshd: root@pts/0",
"root 46439 10230 23:15 ? 00:00:00 sshd: root@pts/1",
"root 46517464390 23:15 pts/1 00:00:00 /bin/sh -c/root/.ansible/tmp/ansible-tmp-1482938153.95-199337961978722/ckl.sh sshd free_form=yes && sleep 0",
"root 46529465170 23:15 pts/1 00:00:00 /bin/bash /root/.ansible/tmp/ansible-tmp-1482938153.95-199337961978722/ckl.sh sshd free_form=yes",
"Wed Dec 28 23:15:54 CST 2016",
"*******************"
]
}
172.16.110.48 | SUCCESS => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 172.16.110.48 closed.\r\n",
"stdout": "root 1019 10 Dec27 ? 00:00:00 /usr/sbin/sshd\r\nroot 43902 10190 21:43 ? 00:00:00 sshd: root@pts/0\r\nroot 46357 10190 23:15 ? 00:00:00 sshd: root@pts/1\r\nroot 46435463570 23:15 pts/1 00:00:00 /bin/sh -c/root/.ansible/tmp/ansible-tmp-1482938153.97-107422068359222/ckl.sh sshd free_form=yes && sleep 0\r\nroot 46447464350 23:15 pts/1 00:00:00 /bin/bash /root/.ansible/tmp/ansible-tmp-1482938153.97-107422068359222/ckl.sh sshd free_form=yes\r\nroot 46449464470 23:15 pts/1 00:00:00 /bin/bash /root/.ansible/tmp/ansible-tmp-1482938153.97-107422068359222/ckl.sh sshd free_form=yes\r\nroot 46450464470 23:15 pts/1 00:00:00 /bin/bash /root/.ansible/tmp/ansible-tmp-1482938153.97-107422068359222/ckl.sh sshd free_form=yes\r\nWed Dec 28 23:15:54 CST 2016\r\n*******************\r\n",
"stdout_lines": [
"root 1019 10 Dec27 ? 00:00:00 /usr/sbin/sshd",
"root 43902 10190 21:43 ? 00:00:00 sshd: root@pts/0",
"root 46357 10190 23:15 ? 00:00:00 sshd: root@pts/1",
"root 46435463570 23:15 pts/1 00:00:00 /bin/sh -c/root/.ansible/tmp/ansible-tmp-1482938153.97-107422068359222/ckl.sh sshd free_form=yes && sleep 0",
"root 46447464350 23:15 pts/1 00:00:00 /bin/bash /root/.ansible/tmp/ansible-tmp-1482938153.97-107422068359222/ckl.sh sshd free_form=yes",
"root 46449464470 23:15 pts/1 00:00:00 /bin/bash /root/.ansible/tmp/ansible-tmp-1482938153.97-107422068359222/ckl.sh sshd free_form=yes",
"root 46450464470 23:15 pts/1 00:00:00 /bin/bash /root/.ansible/tmp/ansible-tmp-1482938153.97-107422068359222/ckl.sh sshd free_form=yes",
"Wed Dec 28 23:15:54 CST 2016",
"*******************"
]
}
页:
[1]