I want to know if it's possible deploy 6 different tasks in parallel (3|3) for 2 different hosts in ansible 2.2.0, because i'm having issues run them in parallel with one playbook, they just run sequencial.
running parallel different task Ansible 2.2.0
871 Views Asked by famg At
2
There are 2 best solutions below
0
On
You can see strategy: free in a combination with when: inventory_hostname == 'hostXX', for example:
- hosts: all
strategy: free
tasks:
- block:
- name: task1
...
- name: task2
...
- name: task3
...
when: inventory_hostname == 'host1'
- block:
- name: task4
...
- name: task5
...
- name: task6
...
when: inventory_hostname == 'host2'
strategy: free means all tasks will run on all hosts in parallel as fast as they can, not waiting for each task to finish on each host. Which task is going to be run on which host is decided by the when clause.
I used block here, so that you only need to write one when for each block, but you don't have to use it, you can write a when on each task.
You can do this with
asynctasks. Something like this:This will start task1a.sh and task1b.sh as async jobs on host1 and host2 respectively and then wait for check_done.sh to return zero.