Example 6
hosts.ini
[centos]
provisioner ansible_connection=local
centos2 ansible_host=192.168.77.22 ansible_port=2345
[ubuntu]
ubuntu1 ansible_host=192.168.77.23
[centos:vars]
ansible_become=true
Tip
Apart from defining hostvars
, which describe only a single host, we can incorporate groupvars
that gather common variables for all remote hosts that belong to the same group.
Try to execute the whoami
command on all hosts.
ansible all -m command -a "whoami"
What is the expected output of the command ?
The command will be run as the root user for all hosts that belong to the centos
group.