How to run ansible playbook task sequentially on a group of hosts

Run ansible task sequentially

How to run ansible playhook on a group of host one by one

Many times you may be in a need to run ansible playbook on a group of hosts one by one. The default behavior of ansible is to run each task in a playbook simultaneously on each host mentioned in the group of host.
For example, in the hosts file, webservers is the group of host

[webservers]
192.2.32.2
192.2.32.4
192.2.32.5

If your ansible playbook have three tasks namely task1, task2 and task3. So if you run the playbook on webserver than task1 will be executed on each the three server simultaneously than task2 would be executed on all three and so on.
To change this behavior if you want to run all three task on one server at once than pickup the second server and run all three task, add the following to your playbook

- hosts: webservers
serial: 1
tasks:
- name: ...

Now if you run the playbook it will be execute all three tasks on a single hosts than picks up the second host to run the tasks.

Leave a Reply

Your email address will not be published. Required fields are marked *