Execute Ansible tasks asynchronously

0
4411
Ansible
Ansible

By default, Ansible tasks are run in blocking mode, that is, each task has to wait for previous task to complete before it can execute.

Just think about when you have some tasks that take really long time to run, so waiting for it to complete is not time-efficient. Fortunately, Ansible provides a way to execute tasks asynchronously, which means, you don’t have to wait for it to complete, and other tasks can be executed.

The provided options are async and poll.


---
- hosts: target

  tasks:
    - shell: COMMAND_TO_EXECUTE
      async: 60
      poll: 15

If poll is not provided, its value is 10 by default, or you just fire-and-forget.

For more info, refer to Ansible documentation – Asynchronous Actions and Polling.