Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible - How to sequentially execute playbook for each host

I am using ansible to script a deployment for an API. I would like this to work sequentially through each host in my inventory file so that I can fully deploy to one machine at a time.

With the out box behaviour, each task in my playbook is executed for each host in the inventory file before moving on to the next task.

How can I change this behaviour to execute all tasks for a host before starting on the next host? Ideally I would like to only have one playbook.

Thanks

like image 672
Lynn Avatar asked Dec 05 '14 12:12

Lynn


People also ask

Does Ansible execute in order?

Task executionBy default, Ansible executes each task in order, one at a time, against all machines matched by the host pattern. Each task executes a module with specific arguments.

How do I run multiple Ansible playbooks at once?

you can run more playbooks using "ansible-playbook [OPTIONS] *. yml" command. This will execute all the playbooks NOT IN PARALLEL WAY, but in serial way, so first one playbook and after the execution, another playbook. This command can be helpful if you have many playbooks.

Which command instructs Ansible to execute the playbook on all the hosts except?

yaml . playbook. yaml. This playbook file instructs Ansible to execute the instructions on all hosts.

Can I run multiple Ansible playbooks in parallel?

Ansible is not designed to run multiple playbooks at the same time in one process - for example, because the tasks differ from playbook to playbook and there is no step "taskA" in playbook1 and playbook2 at the same time. You need to run every playbook in one separate process (like with ansible-playbook ... & ).


2 Answers

Have a closer look at Rolling Updates:

What you are searching for is

- hosts: webservers   serial: 1   tasks:     - name: ... 
like image 116
ProfHase85 Avatar answered Nov 08 '22 20:11

ProfHase85


Using the --forks=1 specify number of parallel processes to use (default=5)

like image 38
Jobin James Avatar answered Nov 08 '22 19:11

Jobin James