check status of async job

752 views
Skip to first unread message

x93...@gmail.com

unread,
Oct 9, 2013, 6:38:21 AM10/9/13
to ansible...@googlegroups.com
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.

Michael DeHaan

unread,
Oct 9, 2013, 10:18:57 AM10/9/13
to ansible...@googlegroups.com
If you fire and forget you can't check status.

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




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

x93...@gmail.com

unread,
Oct 9, 2013, 1:14:51 PM10/9/13
to ansible...@googlegroups.com
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?

Michael DeHaan

unread,
Oct 9, 2013, 1:49:56 PM10/9/13
to ansible...@googlegroups.com
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.




James Cammarata

unread,
Oct 9, 2013, 2:26:27 PM10/9/13
to ansible...@googlegroups.com
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!
James Cammarata <jcamm...@ansibleworks.com>
Sr. Software Engineer, AnsibleWorks, Inc.
http://www.ansibleworks.com/

x93...@gmail.com

unread,
Oct 10, 2013, 5:42:11 AM10/10/13
to ansible...@googlegroups.com
Thank you both for the information. Thought maybe I was missing something.

x93...@gmail.com

unread,
Oct 10, 2013, 10:37:41 AM10/10/13
to ansible...@googlegroups.com
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?

Michael DeHaan

unread,
Oct 10, 2013, 8:07:42 PM10/10/13
to ansible...@googlegroups.com
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


Reply all
Reply to author
Forward
0 new messages