1)在所有主机执行shell

ansible all -m command -a ‘date’

ansible all -m command -a ‘vmstat 1 1 ‘
[root@Oracle12c ~]# ansible all –list-hosts
192.168.8.121
192.168.8.66
指定主机组:

[zabbix]
192.168.8.66
#192.168.8.11
[orabbix]
192.168.8.121
[pc]
#192.168.8.109

[root@Oracle12c ~]# ansible all -m command -a ‘date’
192.168.8.121 | success | rc=0 >>
Wed Jan 3 16:28:15 CST 2018

192.168.8.66 | success | rc=0 >>
Wed Jan 3 00:28:51 PST 2018
2)复制文件到所有目标主机

ansible all -m copy -a “src=/etc/ansible/ansible.cfg dest=/tmp/ansible.cfg owner=root group=root mode=0744”

ansible all -m copy “src=hello.sh dest=/root/hello.sh owner=root group=root mode=0744”
3)远程执行shelljiaoben

a.将服务器脚本分发到远程主机
b.远程调用脚本执行

[root@Oracle12c ~]# ansible all -m command -a ‘/root/hello.sh’
192.168.8.121 | success | rc=0 >>
hello

192.168.8.66 | success | rc=0 >>
hello