Limiting the host’s execution
While testing a playbook, it might make sense to test on a restricted number of machines; for instance, just one. Let’s get started:
- To use the limitation of target hosts on Ansible, we will need a playbook. Create a playbook called
helloworld.yaml
that contains the following content:--- - hosts: all tasks: - ansible.builtin.debug: msg: "Hello, World!"
- We also need to create an inventory with at least two hosts. In my case, I created a file called
inventory
that contains the following content:[hosts] host1.example.com host2.example.com host3.example.com
Let’s run the playbook in the usual way with the following command:
$ ansible-playbook -i inventory helloworld.yaml
By doing this, we will receive the following output:
PLAY [all] **************************************************************************************** TASK [Gathering Facts...