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 ?
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
“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 ?
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.