Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run multiple ansible plays in parallel?

Tags:

ansible

I have a playbook with multiple plays:

---
- hosts: druid-realtime-1
  sudo: true
  roles:
  - { role: druid-realtime, du_rt_id: 1 }

- hosts: druid-realtime-2
  sudo: true
  roles:
  - { role: druid-realtime, du_rt_id: 2 }

How do I tell ansible to run both plays in parallel instead of one after another?

like image 918
pdeva Avatar asked Sep 06 '14 07:09

pdeva


People also ask

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 ... & ).

How do I run an Ansible task in parallel?

If you want to run multiple tasks in a playbook concurrently, use async with poll set to 0. When you set poll: 0 , Ansible starts the task and immediately moves on to the next task without waiting for a result. Each async task runs until it either completes, fails or times out (runs longer than its async value).

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.

What is parallelism Ansible?

Interact with multiple hosts simultaneously, on a per-playbook basis with Ansible's serial keyword. Posted: June 29, 2022 | 3 min read | by Robert Kimani. ImagebyRoyHarrymanfromPixabay. Parallelism describes a software's ability to spawn multiple processes to execute tasks in tandem.


1 Answers

You could do it this way

In your Ansible inventory, group your servers and assign a host variable:

[druid-realtime]
druid-realtime-1 id=1
druid-realtime-2 id=2

Then reference the variable in the playbook:

- hosts: druid-realtime
  sudo: true
  roles: 
    - { role: druid-realtime, du_rt_id: {{ id }} }
like image 176
Ben Whaley Avatar answered Oct 28 '22 08:10

Ben Whaley