Reputation: 3337
I have a simple ansible playbook where I want the first 3 tasks to run in parallel and then the rest to run after those three are done. I've looked at async but i don't quite understand how it gets implemented.
Right now I have this:
---
- name: gkeop
hosts: all
gather_facts: false
tasks:
- name: adminWsInstall
vmware_deploy_ovf:
hostname: '{{ hostname_vcenter }}'
username: '{{ username }}'
password: '{{ password }}'
...
delegate_to: localhost
- name: vcenterInstall
vmware_deploy_ovf:
hostname: '{{ hostname_vcenter }}'
username: '{{ username }}'
password: '{{ password }}'
...
delegate_to: localhost
- name: f5Install
vmware_deploy_ovf:
hostname: '{{ hostname_vcenter }}'
username: '{{ username }}'
password: '{{ password }}'
...
delegate_to: localhost
- name: Cluster Add
template:
src: cluster.sh.j2
dest: /home//cluster.sh
mode: 0777
- name: F5 License
template:
src: f5.sh.j2
dest: /home/f5.sh
mode: 0777
- name: Run cluster add
command: sh /home/cluster.sh
become: true
- name: Run f5 license
command: sh /home/f5.sh
become: true
so do I just add in, for example,
async: 600
poll: 5
to each of the three tasks first tasks and that would make them run in parallel?
Upvotes: 0
Views: 5164
Reputation: 1920
the fourth task should check that the other tasks have finished. Look at this sample playbook:
- hosts: loc
tasks:
- name: sleep 10 seconds
shell: sleep 10
async: 10
poll: 0
register: sleeper1
- name: sleep 10 seconds again
shell: sleep 10
async: 10
poll: 0
register: sleeper2
- name: sleep 10 seconds again
shell: sleep 10
async: 10
poll: 0
register: sleeper3
- name: wait for all 3 tasks
async_status: jid="{{ item }}"
register: job_result
until: job_result.finished
retries: 10
with_items:
- "{{ sleeper1.ansible_job_id }}"
- "{{ sleeper2.ansible_job_id }}"
- "{{ sleeper3.ansible_job_id }}"
- name: next task
debug:
msg: "ready"
The last task runs only if the others are done. Hope that helps.
Upvotes: 2