标签:ansbile
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 | 无关注 |
启动http服务
# 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.定义服务开机启动
# ansible webserver -m service -a "name=httpd enabled=yes"
3.带参数重启网络
# 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.查看服务运行状态,通过匹配字段查找
# 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", ..... } }
本文出自 “深呼吸再出击” 博客,请务必保留此出处http://ckl893.blog.51cto.com/8827818/1887105
标签:ansbile
原文地址:http://ckl893.blog.51cto.com/8827818/1887105