How to patch multiple hosts / servers concurrently using Ansible ?
Environment
- Ansible Engine
Issue
- When patching on one server is done it should not wait for another server to complete patching rather than continue with next tasks.
Resolution
-
The behaviour of Ansible can be controlled with
strategyplugins. -
By default Ansible uses the
linearplugin, All hosts will run each task before any host starts the next task, using the number of forks (default 5) to parallelize. -
Another strategy available is free. Task execution is in lockstep per host batch as defined by serial (default all). Up to the fork limit of hosts will execute each task at the same time and then the next series of hosts until the batch is done, before going on to the next task.
Set the strategy like this:
- hosts: all strategy: free tasks: -
If it is not possible to use free strategy you could set batches with the serial directive.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments