Skip to content

Instantly share code, notes, and snippets.

@guoqiao
Created January 23, 2019 00:01
Show Gist options
  • Save guoqiao/28b18253a1abdb902858e2d733ca90c3 to your computer and use it in GitHub Desktop.
Save guoqiao/28b18253a1abdb902858e2d733ca90c3 to your computer and use it in GitHub Desktop.
Ansible task loop in parallel with async mode
#!/usr/bin/env ansible-playbook
---
- hosts: localhost
gather_facts: no
tasks:
- name: sleep 10s
command: "sleep 10"
loop: "{{range(3)|list}}"
async: 11
poll: 0
register: async_loop
- debug: var=async_loop
- name: wait
async_status:
jid: "{{item.ansible_job_id}}"
mode: status
retries: 11
delay: 1
loop: "{{async_loop.results}}"
register: async_loop_jobs
until: async_loop_jobs.finished
- debug: var=async_loop_jobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment