例:在指定节点上安装tree服务
[root@master ~]#ansible all -m yum -a "state=present name=tree"
例:在指定节点上安装httpd服务
[root@master ~]#ansible all -m yum -a "state=present name=httpd"
[root@client01 tmp]# rpm -qa httpd
httpd-2.2.15-54.el6.centos.x86_64
例:在指定节点上安装tree服务
检查服务是不存在的
[root@hdp-m ~]# ansible dr_exp1 -m shell -a "rpm -qa tree"
[WARNING]: Consider using yum, dnf or zypper module rather than running rpm
192.168.1.142 | SUCCESS | rc=0 >>
127.0.0.1 | SUCCESS | rc=0 >>
192.168.1.137 | SUCCESS | rc=0 >>
执行命令批量安装:
ansible dr_exp1 -m yum -a "state=present name=tree"
执行命令批量删除
[root@hdp-m ~]# ansible dr_exp1 -m yum -a "state=removed name=tree"
[root@hdp-m ~]# ansible dr_exp1 -m yum -a "state=absent name=tree"
原文地址:http://blog.51cto.com/wujianwei/2082898