How do you diagnose a slow playbook step by step?
IntermediateProductionPerformance and Scale
Answer
- Run with
profile_tasksand note the top tasks and the gap between the end of the last task and the recap. - If time is spent before the first task, check inventory loading (
time ansible-inventory --list) and fact gathering. - If it is spread over many tasks, check per-task SSH overhead: ControlPersist, pipelining, DNS delay on the target (
UseDNS), slow shell profiles. - For a single slow host, run
-vvvagainst it and compare with a fast host. - For slow tasks, run the same command by hand on the target to see if Ansible is the cause at all.
A frequent hidden cause is reverse DNS or GSSAPI auth making each SSH login wait a few seconds.
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