In this blog post, I will show you how to run Ansible commands or playbooks against all the hosts in the inventory.
By default, Ansible comes with a pre-defined group called all (or *) that includes all the inventory hosts. Using the all group is very helpful if you want to run a command against all the hosts in the inventory file.
Example
In the following example, I will execute the df command against all the hosts in my inventory without specifying specific hosts or host groups.
ansible all -a df -i hosts
To run Ansible against a single host I can simply use the following command.
ansible hostname -a df -i hosts
To run ansible again multiple hosts I will run the following command.
ansible hostname1,hostname2 -a df -i hosts
Processing…
Success! You're on the list.
Whoops! There was an error and we couldn't process your subscription. Please reload the page and try again.