Skip to content

Example 5

hosts.ini

[centos]
centos1     ansible_connection=local
centos2     ansible_host=192.168.77.22  ansible_port=2345
centos[1:2] ansible_become=true

[ubuntu]
ubuntu1     ansible_host=192.168.77.23

Tip

You can define common variables for a range of remote hosts with the same base name by using the [start:end] notation.

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 have their names start with centos, followed by a number in range from 1 to 2.