Created
March 7, 2019 09:47
-
-
Save snevs/330f34579610d5c635f895aa6f45f504 to your computer and use it in GitHub Desktop.
ansible parallel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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