Fact gathering is the slowest part of a nightly run. How do you cache facts?
AdvancedScenarioPerformance, Testing and CI/CD
Answer
Situation read → Repeated expensive probing.
What I'd do →
[defaults]
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /var/cache/ansible/facts
fact_caching_timeout = 86400
Use Redis for a shared cache across controllers.
Why → smart gathers only when no valid cache exists.
Interview tip → Don't cache facts for fast-changing values like free memory in decisions.
More on Performance, Testing and CI/CD
A playbook that touches 200 hosts takes 40 minutes. Where do you start tuning?IntermediateYou 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