一。安装软件
1.查看是否有安装软件
ansible host31 -m shell -a "rpm -qa |grep httpd"
如果显示host31 | FAILED | rc=1 >> 则表示没安装
如果显示
172.16.10.239 | success | rc=0 >>
httpd-tools-2.2.15-54.el6.centos.x86_64
httpd-2.2.15-54.el6.centos.x86_64
则表示已安装。
2.使用yum模块安装httpd:
ansible host31 -m yum -a “name=httpd”
二。启动服务
1.查看服务是否是启动状态
ansible a -m shell -a "service httpd status"
也可以ansible a -m command -a "service httpd status"
172.16.10.239 | FAILED | rc=3 >>
httpd is stopped
2.使用service模块启动httpd
ansible host31 -m service -a "name=httpd state=started"
关闭httpd
ansible host31 -m service -a "name=httpd state=stopped"
三 。
ansible host31 -m service -a "name=httpd enabled=yes state=restarted"
四。
ansible host31 -m yum -a "name=httpd state=absent"
原文地址:http://406647516.blog.51cto.com/2249087/1923841