How to run multiple playbooks in parallel?

Viewed 3072

I have multiple playbooks included in one playbook. Now when I play it, it starts with first one, when finishes first then the second one runs. I want to play all the included playbooks in parallel. This is my playbook:

---
- name: deploy A
  import_playbook: deploy-A.yml
- name: deploy B
  import_playbook: deploy-B.yml
- name: deploy C
  import_playbook: deploy-C.yml
- name: deploy D
  import_playbook: deploy-D.yml
3 Answers

A playbook is "one process" that runs on multiple hosts - to be more precise - one task runs on multiple hosts, but tasks are running step by step.

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

I want to play all the included playbooks in parallel

That's not possible.

The easiest method would be to split the playbook in different .yml files, and execute each from a different terminal.

Or run them with the ansible-parrelel pip package.

for running multiple tasks in a playbook concurrently; you can use async and poll keyword. async keyword: triggers the job in background and can be checked later and its value will be the maximum time that ansible will wait for the command to complete. value of poll indicates to ansible how often to poll to check a bout the task completion.(default is 10s and set to 0 for running concurrently multiple tasks in a playbook)

To check on the job status later: use the async_status module, this module requires the job or task identifier as its parameter.

passing it the job ID that was returned when you ran the original job in the background.

Related