# What are fire and forget tasks ?

**URL:** <https://forum.ansible.com/t/what-are-fire-and-forget-tasks/24952>\
**Category:** Ansible Project\
**Created:** [July 11, 2017, 2:01pm UTC](https://forum.ansible.com/t/what-are-fire-and-forget-tasks/24952 "2017-07-11T14:01:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luvpreet\_Singh](https://avatars.discourse-cdn.com/v4/letter/l/a5b964/32.png) [@Luvpreet\_Singh](https://forum.ansible.com/u/Luvpreet_Singh)\
**Post date:** [July 11, 2017, 2:01pm UTC](https://forum.ansible.com/t/what-are-fire-and-forget-tasks/24952/1 "2017-07-11T14:01:29Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [July 11, 2017, 5:20pm UTC](https://forum.ansible.com/t/what-are-fire-and-forget-tasks/24952/2 "2017-07-11T17:20:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Luvpreet\_Singh](https://avatars.discourse-cdn.com/v4/letter/l/a5b964/32.png) [@Luvpreet\_Singh](https://forum.ansible.com/u/Luvpreet_Singh)\
**Post date:** [July 12, 2017, 6:18am UTC](https://forum.ansible.com/t/what-are-fire-and-forget-tasks/24952/3 "2017-07-12T06:18:16Z")

</div>

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 ?

```auto
  - 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 ?

```

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [July 12, 2017, 7:21am UTC](https://forum.ansible.com/t/what-are-fire-and-forget-tasks/24952/4 "2017-07-12T07:21:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 14, 2017, 3:12pm UTC](https://forum.ansible.com/t/what-are-fire-and-forget-tasks/24952/5 "2017-07-14T15:12:28Z")

</div>

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

- name: Reboot the system  
&nbsp;&nbsp;&nbsp;shell: sleep 2 && shutdown -r now "Ansible reboot triggered"  
&nbsp;&nbsp;&nbsp;async: 1  
&nbsp;&nbsp;&nbsp;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.

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [July 15, 2017, 11:36am UTC](https://forum.ansible.com/t/what-are-fire-and-forget-tasks/24952/6 "2017-07-15T11:36:07Z")

</div>

Thanks Kai
