七、Ansible系统类模块(二)

service模块

管理远程主机上的服务,启动停止重启等。
注意:使用该模块,服务必须能够通过systemctl或service管理,如service nginx start或者systemctl start nginx,否则无法使用。

案例

1、启动db_servers资源列表中的主机nginx服务

$ ansible db_servers -m service -a "name=nginx state=started"

2、停止nginx服务

$ ansible db_servers -m service -a "name=nginx state=stopped"

3、将nginx服务加入开机启动项

$ ansible db_servers -m service -a " name='nginx' enabled=yes"

常用参数

  • name
    指定需要操作的服务名称,比如nginx

  • state
    指定服务的状态,此参数的可用值有started、stopped、restarted、reloaded,含义分别为启动/停止/重启/重新读取配置

  • enabled
    指定是否将服务设置为开机启动项,设置为yes表示将对应服务设置为开机启动,设置为no表示不会开机启动。

参考资料:
转载于朱老师博客

posted @ 2021-05-31 17:44  努力吧阿团  阅读(52)  评论(0)    收藏  举报