Skip to content

Instantly share code, notes, and snippets.

@snevs
Created March 7, 2019 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snevs/330f34579610d5c635f895aa6f45f504 to your computer and use it in GitHub Desktop.
Save snevs/330f34579610d5c635f895aa6f45f504 to your computer and use it in GitHub Desktop.
ansible parallel
---
- name: Run tasks in parallel
hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Pretend to create instances
command: "sleep {{ item }}" # Instead of calling a long running operation at a cloud provider, we just sleep.
with_items:
- 6
- 8
- 7
register: _create_instances
async: 600 # Maximum runtime in seconds. Adjust as needed.
poll: 0 # Fire and continue (never poll)
- name: Wait for creation to finish
async_status:
jid: "{{ item.ansible_job_id }}"
register: _jobs
until: _jobs.finished
delay: 5 # Check every 5 seconds. Adjust as you like.
retries: 10 # Retry up to 10 times. Adjust as needed.
with_items: "{{ _create_instances.results }}"
- name: Run tasks in sequence
hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Pretend to create instances
command: "sleep {{ item }}" # Instead of calling a long running operation at a cloud provider, we just sleep.
with_items:
- 6
- 8
- 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment