Parallel Tasks Execution in Ansible

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 !

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.

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

In other way ?

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:

See the discussion here for some other ideas:

https://github.com/ansible/proposals/issues/31

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

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