Asynchronous versus synchronous actions
As we have seen in this book so far, Ansible plays are executed in sequence, with each task running to completion before the next task is started. Although this is often advantageous for flow control and logical sequencing, there are times when you may not want this. In particular, it might be the case that a particular task runs for longer than the configured SSH connection timeout, and as Ansible uses SSH to perform its automation tasks on most platforms, this would be an issue.
Fortunately, Ansible tasks can be run asynchronously—that is to say, tasks can be run in the background on the target host and polled on a regular basis. This is in contrast to synchronous tasks, where the connection to the target host is kept open until the task completes (which runs the risk of a timeout occurring).
As ever, let’s explore this through a practical example. Suppose we have two servers in a simple INI-formatted inventory:
[frontends...