# check status of async job

**URL:** <https://forum.ansible.com/t/check-status-of-async-job/13639>\
**Category:** Ansible Project\
**Created:** [October 9, 2013, 10:38am UTC](https://forum.ansible.com/t/check-status-of-async-job/13639 "2013-10-09T10:38:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![x9353x](https://avatars.discourse-cdn.com/v4/letter/x/e36b37/32.png) [@x9353x](https://forum.ansible.com/u/x9353x)\
**Post date:** [October 9, 2013, 10:38am UTC](https://forum.ansible.com/t/check-status-of-async-job/13639/1 "2013-10-09T10:38:21Z")

</div>

I am trying to run async jobs with ‘poll=0’ (fire & forget) and then check the job status via async\_status. However, I don’t know how to properly check for job completion.

Here’s my playbook snippet:

- command: /bin/sleep 10  
async: 25  
poll: 0  
register: sleeper

- async\_status: jid={{ sleeper.ansible\_job\_id }}  
register: job\_result  
until: job\_result.finished  
retries: 10  
delay: 1

Of course, the ‘until: job\_result.finished’ fails because the ‘finished’ attribute is NOT populated until the job has finished. I have tried doing ‘until: hasattr(job\_result,‘finished’)’ as well, but this also fails.

How should I be doing this kind of thing?

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 9, 2013, 2:18pm UTC](https://forum.ansible.com/t/check-status-of-async-job/13639/2 "2013-10-09T14:18:57Z")

</div>

If you fire and forget you can’t check status.

You should consider not doing fire-and-forget and setting a poll interval

---

<div class="post-metadata">

**Author:** ![x9353x](https://avatars.discourse-cdn.com/v4/letter/x/e36b37/32.png) [@x9353x](https://forum.ansible.com/u/x9353x)\
**Post date:** [October 9, 2013, 5:14pm UTC](https://forum.ansible.com/t/check-status-of-async-job/13639/3 "2013-10-09T17:14:51Z")

</div>

Thanks, but my experience with adding the poll interval seems to make an async task into a blocking, synchronous task. The playbook does not proceed until the job is finished or the timeout is reached.

What I’d like to do is launch tasks A & B asynchronously so that they execute in parallel. Then I want the playbook to continue with task C only after tasks A & B have both finished.

Is this possible?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 9, 2013, 5:49pm UTC](https://forum.ansible.com/t/check-status-of-async-job/13639/4 "2013-10-09T17:49:56Z")

</div>

Yes, I’m aware that polling does that, it’s intentional.

There’s no way to poll a ‘fire and forget’ job unless you just have it touch a file when you are done.

There’s a do/until loop in 1.4 you could combine with the stat module if you wanted for that purpose.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [October 9, 2013, 6:26pm UTC](https://forum.ansible.com/t/check-status-of-async-job/13639/5 "2013-10-09T18:26:27Z")

</div>

No, it is not currently possible to use async in this manner. Please feel free to open a feature request for this on github.

Thanks!

---

<div class="post-metadata">

**Author:** ![x9353x](https://avatars.discourse-cdn.com/v4/letter/x/e36b37/32.png) [@x9353x](https://forum.ansible.com/u/x9353x)\
**Post date:** [October 10, 2013, 9:42am UTC](https://forum.ansible.com/t/check-status-of-async-job/13639/6 "2013-10-10T09:42:11Z")

</div>

Thank you both for the information. Thought maybe I was missing something.

---

<div class="post-metadata">

**Author:** ![x9353x](https://avatars.discourse-cdn.com/v4/letter/x/e36b37/32.png) [@x9353x](https://forum.ansible.com/u/x9353x)\
**Post date:** [October 10, 2013, 2:37pm UTC](https://forum.ansible.com/t/check-status-of-async-job/13639/7 "2013-10-10T14:37:41Z")

</div>

May I suggest a simple code change here, for consideration by the group?

In the async\_status module, always return the ‘finished’ attribute (with a 0 or 1 value) instead of doing so ONLY when the job is finished. This would make it trivial to perform the parallelization/waiting that today is not available, using the do…until mentioned in the original post. The code change to async\_status would probably be as simple as changing line 84:

module.exit\_json(results\_file=log\_path, ansible\_job\_id=jid, started=1, finished=0)

More general question: how would I check for the presence of an attribute on a result register?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 11, 2013, 12:07am UTC](https://forum.ansible.com/t/check-status-of-async-job/13639/8 "2013-10-11T00:07:42Z")

</div>

Yep, open to patches if you’d like to add this and test to make sure it’s still operational/etc.

“More general question: how would I check for the presence of an attribute on a result register?”

Offhand, untested:

when: foo.rc is defined
