How do you speed up long-running tasks across many hosts?
IntermediateProductionPerformance and Scale
Answer
Use async with poll: 0 to start the task on all hosts at once, regardless of forks, then wait for completion with async_status.
- ansible.builtin.command: /opt/app/bin/reindex
async: 7200
poll: 0
register: reindex
- ansible.builtin.async_status:
jid: "{{ reindex.ansible_job_id }}"
register: job
until: job.finished
retries: 240
delay: 30
Good for patching, backups, large downloads and reindexing. Be careful that starting everything at once can overload shared resources (the mirror, storage), so combine it with throttle where needed.
More on Performance and Scale
Why can Ansible be slower than a shell script for 100 servers, and what dominates the time?BeginnerHow do you choose the `forks` value?BeginnerWhat is SSH pipelining and why does it help?BeginnerWhich SSH settings matter for performance and stability?IntermediateHow do you find out which tasks are slow?BeginnerHow do you reduce the cost of fact gathering?Intermediate