What are fire and forget tasks ?

362 views
Skip to first unread message

Luvpreet Singh

unread,
Jul 11, 2017, 10:01:29 AM7/11/17
to Ansible Project
I have read the asynchronous actions and polling in Ansible docs. But I could not understand it.

I understand that poll means the time interval after which the status of the job will be checked.

I think Async means the interval for which to keep the connection open. If yes, What will happen after the connection is closed ? Will the task be completed ?

And I really did not understand the fire and forget tasks.

Can somebody please make it a bit clearer with the help of an easy example ?

Philippe Eveque

unread,
Jul 11, 2017, 1:21:00 PM7/11/17
to ansible...@googlegroups.com
Hi,

here is an example: trigger a reboot (no need to wait)

do not wait for task completion -  poll:0 
you cannot wait in that case as the System will reboot breaking the ssh connection.



- name: Reboot the system
  shell: sleep 2 && shutdown -r now "Ansible reboot triggered"
  async: 1
  poll: 0
 
another example would be to trigger an action that take a long time but you don't care about the result
like: recursively delete a whole hierarchy of directories/files on a system


hope this help.


--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a10abc4e-b130-4029-9020-d40ad2362508%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Luvpreet Singh

unread,
Jul 12, 2017, 2:18:16 AM7/12/17
to Ansible Project
Thanks Philippe,

"Poll - 0" means that never check the status as the connection will be broken. What does "async - 1" means  ?

Can you explain this example to me ?

  - name: simulate long running op (15 sec), wait for up to 45 sec, poll every 5 sec
    command: /bin/sleep 15
    async: 45
    poll: 5

What does async : 45 means here ?


On Tuesday, July 11, 2017 at 10:51:00 PM UTC+5:30, Philippe Eveque wrote:
Hi,

here is an example: trigger a reboot (no need to wait)

do not wait for task completion -  poll:0 
you cannot wait in that case as the System will reboot breaking the ssh connection.



- name: Reboot the system
  shell: sleep 2 && shutdown -r now "Ansible reboot triggered"
  async: 1
  poll: 0
 
another example would be to trigger an action that take a long time but you don't care about the result
like: recursively delete a whole hierarchy of directories/files on a system


hope this help.

2017-07-11 16:01 GMT+02:00 Luvpreet Singh <s.luvp...@gmail.com>:
I have read the asynchronous actions and polling in Ansible docs. But I could not understand it.

I understand that poll means the time interval after which the status of the job will be checked.

I think Async means the interval for which to keep the connection open. If yes, What will happen after the connection is closed ? Will the task be completed ?

And I really did not understand the fire and forget tasks.

Can somebody please make it a bit clearer with the help of an easy example ?

--
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.
To post to this group, send email to ansible...@googlegroups.com.

Philippe Eveque

unread,
Jul 12, 2017, 3:22:08 AM7/12/17
to ansible...@googlegroups.com
this is the maximum allocated run time set for the task 

in your example:


- run  the simulated long running task for a max of 45 s (in the case of long running task, you do not want it to run for ever)
- poll status every 5 second (so every 5 seconds there is to check the status like whether the task ended )

in my case I should have set async to 2 o 3 but it does not really matter as I do not wait at all (poll 0)


HTH
Phil


To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ff0b5aab-f2da-4def-8a01-1036481a6951%40googlegroups.com.

Kai Stian Olstad

unread,
Jul 14, 2017, 11:12:44 AM7/14/17
to ansible...@googlegroups.com
On 12. juli 2017 09:21, Philippe Eveque wrote:
> in my case I should have set async to 2 o 3 but it does not really matter
> as I do not wait at all (poll 0)

If you were refereeing to this task, this statement is not entirely correct.

- name: Reboot the system
shell: sleep 2 && shutdown -r now "Ansible reboot triggered"
async: 1
poll: 0

To make this task not fail it's important that async is is less that the
sleep. If not it might fail because the host has rebootet before ansible
is finished with the task.


--
Kai Stian Olstad

Philippe Eveque

unread,
Jul 15, 2017, 7:36:29 AM7/15/17
to ansible...@googlegroups.com
Thanks Kai


--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages