Ansible可同时操作属于一个组的多台主机,组与主机之间关系配置在inventory文件中,inventory默认的配置文件是/etc/ansible/hosts
1、在/etc/ansible/hosts文件中配置两个组,分别为test1和test2
[test1]
192.168.144.129
[test2]
192.168.144.130
1.1、对一个组操作
[root@client01 ansible]# ansible test1 -m ping
192.168.144.129 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}
1.2、对两个组同时操作
[root@client01 ansible]# ansible test1:test2 -m ping
192.168.144.130 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}
192.168.144.129 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}
除了默认使用/etc/ansible/hosts,还可用通过-i选项指定inventory文件
[root@client01 ansible]# ansible all -i /home/zhuwan/ansible/hosts -m ping
192.168.144.129 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}