Ansible模块[08]:service
应用
- service模块可以帮助我们管理远程主机上的服务。
参数
-
name:用于指定需要操作的服务名称。
-
state:用于指定服务的状态。
- started:启动对应服务。
- stopped:停止对应服务。
- restarted:重启对应服务。
- reloaded:重新加载对应服务。
-
enabled:用于指定是否将服务设置为开机启动项。
- 设置为yes表示将对应服务设置为开机启动。
- 设置为no表示对应服务不会开机启动。
-
args:命令行上提供的其他参数。
-
pattern:如果服务不响应status命令,请指定要查找的子字符串可以在“ps”命令的输出中找到,作为状态的替代结果。如果找到该字符串,则假定服务已启动。
示例:
1、启动服务httpd(如果未启动)
anisble 10.0.0.12 -m service -a 'name=httpd state=started'
2、停止服务httpd(如果已启动)
anisble 10.0.0.12 -m service -a 'name=httpd state=stopped'
3、在所有情况下,重新启动服务httpd
anisble 10.0.0.12 -m service -a 'name=httpd state=restarted'
4、在所有情况下,重新加载服务httpd
anisble 10.0.0.12 -m service -a 'name=httpd state=reloaded'
5、设置开机启动httpd
anisble 10.0.0.12 -m service -a 'name=httpd enabled=yes'
6、基于某个配置文件启动
anisble 10.0.0.12 -m service -a 'name=xxx pattern=/usr/bin/xxx.conf state=started'
7、重新启动接口eth0的网络服务
anisble 10.0.0.12 -m service -a 'name=network state=restarted args=eth0'

浙公网安备 33010602011771号