跳转至

10. systemd模块

8. systemd模块

1. 作用

# 远程开启关闭服务

2. 案例

#1. 远程查看crond服务状态
ansible ali -m shell -a "systemctl status crond"

#2. 远程查看crond服务是否开机自启
ansible ali -m shell -a "systemctl list-unit-files|grep crond"

#3. 远程开启关闭crond服务
ansible ali -m systemd -a "name=crond state=stopped"
ansible ali -m systemd -a "name=crond state=started"

3. 案例2

#1. 检查是否安装nginx
ansible ali -m shell -a "rpm -qa nginx"

#2. 启动nginx
ansible ali -m systemd -a "name=nginx state=started enabled=yes"
ansible ali -m systemd -a "name=nginx state=restarted"

#3. 查看进程
ansible ali -m shell  -a "ps -ef|grep nginx"

#4. 关闭防火墙
ansible ali -m shell  -a "iptables -F"

最后更新: 2022-02-18 11:26:47