Example 8
hosts.yml
centos:
hosts:
provisioner:
ansible_connection: local
centos1:
ansible_host: '192.168.77.22'
ansible_port: 2345
ubuntu:
hosts:
ubuntu1:
ansible_host: '192.168.77.23'
linux:
children:
centos:
ubuntu:
vars:
ansible_become: true
Tip
The YAML
file format is currently the most popular solution for building Ansible inventories, although the default inventory format is JSON
.
Try to execute the whoami
command on all hosts.
ansible all -m command -a "whoami"
Add ansible_become: false
to the description of centos1
(indentation should match ansible_port
and ansible_host
) and run the command again.
What is the expected output of the command ?
The command will be run as the root user for all hosts except centos1
. This example illustrates that hostvars
take precedence over groupvars
.