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?
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 ... & ).
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).
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.
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.
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 }} }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With