Why can Ansible be slower than a shell script for 100 servers, and what dominates the time?
BeginnerProductionPerformance and Scale
Answer
Ansible does far more per step: for each task and host it opens or reuses an SSH connection, creates a temp dir, transfers a module payload, executes Python, parses JSON, and cleans up. Fact gathering adds a large setup run at the start of every play, and the default linear strategy makes each task wait for the slowest host, with only 5 hosts in parallel (the default forks).
In real playbooks the time sits in three places: fact gathering, a large number of small tasks, and slow tasks such as package installs or downloads. Measure with profile_tasks before tuning.
More on Performance and Scale
How 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?IntermediateWhat is Mitogen for Ansible and would you use it?Advanced