Skip to content

Instantly share code, notes, and snippets.

@versionsix
Created July 12, 2018 10:11
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 versionsix/833eadc91b5e578add3da7f9e5e16c64 to your computer and use it in GitHub Desktop.
Save versionsix/833eadc91b5e578add3da7f9e5e16c64 to your computer and use it in GitHub Desktop.
Ansible async task snippet
---
- hosts: localhost
connection: local
tasks:
- name: simulate long running op, allow to run for 16 sec, fire and forget
command: "/bin/sleep {{ item }}"
async: 16
register: my_async_job
poll: 0
loop: [1, 3, 15, 4]
- name: 'SLEEP - check on async task'
async_status: jid="{{ item.ansible_job_id }}"
register: job_result
loop: "{{ my_async_job.results }}"
until: job_result.finished
retries: 30
loop_control:
label: "Current task: {{ item.item }}" # add custom message
- debug:
msg: "Play ended 😁"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment