A playbook that touches 200 hosts takes 40 minutes. Where do you start tuning?
IntermediateScenarioPerformance, Testing and CI/CD
Answer
Situation read → Unknown bottleneck; measure first.
What I'd do →
- Enable timing callbacks:
callbacks_enabled = profile_tasks, timerinansible.cfg. - Raise
forks(for example 50), enablepipelining, and SSHControlPersist. - Turn off or reduce fact gathering and add fact caching.
- Replace loops of package installs with one
name: [list]call. - Use
asyncfor long independent tasks andstrategy: freewhere safe.
[defaults]
forks = 50
gathering = smart
callbacks_enabled = profile_tasks, timer
[ssh_connection]
pipelining = True
ssh_args = -o ControlMaster=auto -o ControlPersist=60s
Why → Most time is connection overhead and slow tasks; profiling points at the few that matter.
Interview tip → Say "measure, then tune" and name profile_tasks.
More on Performance, Testing and CI/CD
You install 15 packages with a loop and it is slow.BeginnerHow would you test a role in CI before it reaches production?IntermediateWhat would a Molecule `verify.yml` check for an Nginx role?IntermediateMolecule's idempotence step fails. How do you find the offending task?IntermediateDesign a CI pipeline for an Ansible repo.Advanced`--check` shows no change but the real run changes things. Why?Advanced