|
ansible service模块
参数选项来自官网,如果有出入,以官网为主
参数
| 是否必须 | 默认 | 选项 | 说明 | arguments | no |
|
| 命令行参数
| enabled | no |
| yes
no
| 设置服务是否开机启动
| name | yes |
|
| 服务名称 | pattern | no |
|
| 定义一个模式,如果通过status指令来查看服务的状态时,没有响应,就会通过ps指令在进程中根据该模式进行查找,如果匹配到,则认为该服务依然在运行 | runlevel | no | default |
| 服务运行级别 | sleep | no |
|
| 设置start和stop直接的时间间隔
| state | no |
| started
stopped
restarted
reloaded
| 启动
停止
重启
重载
| use | no | auto |
| 无关注 |
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
| # ansible webserver -m service -a "name=httpd state=started"
172.16.110.48 | SUCCESS => {
"changed": true,
"name": "httpd",
"state": "started",
"status": {
"ActiveEnterTimestampMonotonic": "0",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "inactive",
"After": "network.target remote-fs.target basic.target tmp.mount nss-lookup.target -.mount systemd-journald.socket system.slice",
"AllowIsolate": "no",
"AssertResult": "no",
.......
//too long
}
}
172.16.110.47 | SUCCESS => {
"changed": true,
"name": "httpd",
"state": "started",
"status": {
"ActiveEnterTimestampMonotonic": "0",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "inactive",
"After": "tmp.mount remote-fs.target network.target system.slice -.mount systemd-journald.socket basic.target nss-lookup.target",
"AllowIsolate": "no",
"AssertResult": "no",
.......
//too long
}
}
|
2.定义服务开机启动
1
| # ansible webserver -m service -a "name=httpd enabled=yes"
|
3.带参数重启网络
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
| # ansible webserver -m service -a "name=network state=restarted arguments=ens33"
[WARNING]: Ignoring "arguments" as it is not used in "systemd"
[WARNING]: Ignoring "arguments" as it is not used in "systemd"
172.16.110.47 | SUCCESS => {
"changed": true,
"name": "network",
"state": "started",
"status": {
"ActiveEnterTimestamp": "Tue 2016-12-27 17:28:43 CST",
"ActiveEnterTimestampMonotonic": "16144366",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "active",
"After": "NetworkManager-wait-online.service systemd-journald.socket system.slice basic.target NetworkManager.service iptables.service ip6tables.service network-pre.target",
"AllowIsolate": "no",
.......
}
}
172.16.110.48 | SUCCESS => {
"changed": true,
"name": "network",
"state": "started",
"status": {
"ActiveEnterTimestamp": "Tue 2016-12-27 17:33:45 CST",
"ActiveEnterTimestampMonotonic": "11367077",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "active
"After": "basic.target NetworkManager.service NetworkManager-wait-online.service systemd-journald.socket system.slice network-pre.target ip6tables.service iptables.service
.....
|
4.查看服务运行状态,通过匹配字段查找
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
34
35
| # ansible webserver -m service -a "name=atd pattern=/usr/sbin/atd state=started"
[WARNING]: Ignoring "pattern" as it is not used in "systemd"
[WARNING]: Ignoring "pattern" as it is not used in "systemd"
172.16.110.47 | SUCCESS => {
"changed": false,
"name": "atd",
"state": "started",
"status": {
"ActiveEnterTimestamp": "Tue 2016-12-27 17:28:34 CST",
"ActiveEnterTimestampMonotonic": "6416348",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "active",
"After": "system.slice systemd-user-sessions.service basic.target systemd-journald.socket syslog.target",
"AllowIsolate": "no",
"AssertResult": "yes",
.....
}
}
172.16.110.48 | SUCCESS => {
"changed": false,
"name": "atd",
"state": "started",
"status": {
"ActiveEnterTimestamp": "Tue 2016-12-27 17:33:40 CST",
"ActiveEnterTimestampMonotonic": "5455742",
"ActiveExitTimestampMonotonic": "0",
"ActiveState": "active",
"After": "basic.target systemd-user-sessions.service syslog.target systemd-journald.socket system.slice",
"AllowIsolate": "no",
"AssertResult": "yes",
.....
}
}
|
|
|