# Parallel Tasks Execution in Ansible

**URL:** <https://forum.ansible.com/t/parallel-tasks-execution-in-ansible/28276>\
**Category:** Ansible Project\
**Created:** [August 7, 2018, 6:34am UTC](https://forum.ansible.com/t/parallel-tasks-execution-in-ansible/28276 "2018-08-07T06:34:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://forum.ansible.com/u/Saurabh)\
**Post date:** [August 7, 2018, 6:34am UTC](https://forum.ansible.com/t/parallel-tasks-execution-in-ansible/28276/1 "2018-08-07T06:34:25Z")

</div>

Hi,

I would like to execute parallel tasks ?

Below Example

- include: a.yml

- include: b.yml

a.yml runs and b.yml should also run,

b.yml shouldn’t wait for completion of a.yml.

is there any way to run parallel tasks ?

Thank you !

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [August 7, 2018, 6:48am UTC](https://forum.ansible.com/t/parallel-tasks-execution-in-ansible/28276/2 "2018-08-07T06:48:55Z")

</div>

One simple way is to put the tasks in separate playbooks, then:

ansible-playbook […opts…] a.yml \> a.out 2\>&1 &

ansible-playbook […opts…] b.yml \> b.out 2\>&1 &  
ansible-playbook […opts…] c.yml \> c.out 2\>&1 &

ansible-playbook […opts…] d.yml \> d.out 2\>&1 &

Or if you are doing things manually, run them in separate terminals.

Regards, K.

---

<div class="post-metadata">

**Author:** ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://forum.ansible.com/u/Saurabh)\
**Post date:** [August 7, 2018, 11:01am UTC](https://forum.ansible.com/t/parallel-tasks-execution-in-ansible/28276/3 "2018-08-07T11:01:17Z")

</div>

Not this way…I can’t places tasks in different playbook…

In other way ?

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [August 7, 2018, 11:12am UTC](https://forum.ansible.com/t/parallel-tasks-execution-in-ansible/28276/4 "2018-08-07T11:12:21Z")

</div>

If you can’t place the tasks in different playbooks, then they are not truly independent. Why can you not use separate playbooks?

Also, you could use tags to achieve something similar. Tag your tasks “a”, “b”, “c” etc, then:

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [August 7, 2018, 11:39am UTC](https://forum.ansible.com/t/parallel-tasks-execution-in-ansible/28276/5 "2018-08-07T11:39:19Z")

</div>

See the discussion here for some other ideas:

[https://github.com/ansible/proposals/issues/31](https://github.com/ansible/proposals/issues/31)

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [August 7, 2018, 3:00pm UTC](https://forum.ansible.com/t/parallel-tasks-execution-in-ansible/28276/6 "2018-08-07T15:00:42Z")

</div>

Have you tried either one of the following?

1. adding tag to each yaml include file?  
Actually change the include to import\_task and add a tag so you can run each yaml file using --tag with ansible-playbook  
i.e

instead of

- include: a.yml

- include: b.yml

Do this

- import\_tasks: a.yml  
tags: a\_yml

- import\_tasks: b.yml  
tags: b\_yml

ansible-playbook master\_playbook.yml --tags a\_yml &

ansible-playbook master\_playbook.yml --tags b\_yml &

1. use async on each task

- include: a.yml

async: 360  
poll: 0

- include: b.yml

async: 360  
poll: 0

using “poll: 0” mean it doesn’t wait for a.yml to finish executing and it will immediately execute b.yml

Regards,  
T

---

<div class="post-metadata">

**Author:** ![stan.varlamov](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@stan.varlamov](https://forum.ansible.com/u/stan.varlamov)\
**Post date:** [August 8, 2018, 5:26am UTC](https://forum.ansible.com/t/parallel-tasks-execution-in-ansible/28276/7 "2018-08-08T05:26:21Z")

</div>

I’m using AWX Workflow templates for basic sequencing and execution control of playbooks. There is some extra hardware required, but software-wise AWX is relatively low barrier to start running playbooks in a more organized manner than from the CLI. I wouldn’t expect Ansible to provide a true multi-threading and parallel execution engine on par with, say, Java 8, with locks, messages, controlled shared access to runtime memory, etc., so to me it’s more about adjusting to the capabilities of the core toolset than asking for it to become what it’s not meant to be
