# Any plans for an "await" to go with async stuff?

**URL:** <https://forum.ansible.com/t/any-plans-for-an-await-to-go-with-async-stuff/25438>\
**Category:** Ansible Developer\
**Created:** [September 8, 2017, 1:51pm UTC](https://forum.ansible.com/t/any-plans-for-an-await-to-go-with-async-stuff/25438 "2017-09-08T13:51:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![neil1](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@neil1](https://forum.ansible.com/u/neil1)\
**Post date:** [September 8, 2017, 1:51pm UTC](https://forum.ansible.com/t/any-plans-for-an-await-to-go-with-async-stuff/25438/1 "2017-09-08T13:51:00Z")

</div>

It seems like it would be really useful to have “await” functionality to go with the async task stuff - instead of poll or “fire-and-forget”, the ability to start async tasks that are going to take a while and receive handles to them which can then be used later in the play to wait for them to succeed or fail to continue.

If this is already possible, I’d appreciate some pointers on how to do it. I didn’t spend a ton of time with the async docs, but I didn’t see anything that seemed to indicate this functionality to me. Did quick searches here, online and on the project mailing list and didn’t see anything either.

I was thinking of something like…

`

# We’re working normally (sequentially)…

- name: Init/update all Git submodules  
command: git submodule update --init

# OK, now we’re ready to kick off some tasks that are independent of each other

# and can take quite a while to complete:

- name: Start independent asynchronous background tasks…  
async:

# I structured these as a dict to emphasis that they’re not running in

# order, like a list might suggest. The keys (user-defined - whatever

# you want) could then be used to access results on the handle.

tasks:  
git\_lfs\_pull:  
name: Pull Git LFS files  
command: git lfs pull

bundle\_install:  
name: Install gems with Bundler  
bundler:  
state: present

# A handle you receive back that can be used to wait for the tasks.

register: async\_handle

# Now we can keep working in sequence…

- name: Install some Python packages with Pip  
with\_items:
- pathlib2
- docker-compose  
pip:  
name: “{{ item }}”

# …whatever else as usual…

# OK, now we’re at the point where we need the async tasks to be done

- name: Wait for async tasks to be done.  
await:  
handle: “{{ async\_handle }}”

# Once here, we know the async stuff is done and successful (or failed with the

# usual message, etc.)

- name: Kick off a build…  
command: docker-compose build .

`

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [September 8, 2017, 2:30pm UTC](https://forum.ansible.com/t/any-plans-for-an-await-to-go-with-async-stuff/25438/2 "2017-09-08T14:30:21Z")

</div>

I think async\_status will do what you want already. I’ve not had cause to use it myself but there’s an example about halfway down this page

[http://docs.ansible.com/ansible/latest/playbooks\_async.html](http://docs.ansible.com/ansible/latest/playbooks_async.html)

```auto
---
# Requires ansible 1.8+
- name: 'YUM - fire and forget task'
  yum: name=docker-io state=installed
  async: 1000
  poll: 0
  register: yum_sleeper

- name: 'YUM - check on fire and forget task'
  async_status: jid={{ yum_sleeper.ansible_job_id }}
  register: job_result
  until: job_result.finished
  retries: 30

```

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![neil1](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@neil1](https://forum.ansible.com/u/neil1)\
**Post date:** [September 8, 2017, 5:15pm UTC](https://forum.ansible.com/t/any-plans-for-an-await-to-go-with-async-stuff/25438/3 "2017-09-08T17:15:45Z")

</div>

Cool, thanks… I found that example far from intuitive, and it wasn’t clear to me when I looked at it that it facilitated firing off many different tasks at different points, but after loading it up and messing with it for a while I think i have an ugly but functional version of what I was looking for, so I should be able to sugar that up somehow into something like what I want 🙂

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [September 11, 2017, 10:30am UTC](https://forum.ansible.com/t/any-plans-for-an-await-to-go-with-async-stuff/25438/4 "2017-09-11T10:30:02Z")

</div>

Please share it if you can.

By all means create a pull request if you have better examples that are easier to understand. Examples drawn from real-world problems being solved are good to see if they are general enough for others to understand.

All the best,

Jon
