Interview Prep/Ansible/Performance and Scale

How do you reduce the cost of fact gathering?

IntermediateProductionPerformance and Scale
Answer
  • gather_facts: false on plays that do not use facts.
  • gather_subset: [min, network] (or !hardware) to avoid slow hardware probes.
  • Fact caching with gathering = smart and a jsonfile or Redis cache, so unchanged hosts skip the setup module.
  • Use gather_facts: false and then a single early setup for what you need, instead of re-gathering in every play of the playbook.
[defaults]
gathering = smart
fact_caching = redis
fact_caching_connection = cache.internal:6379:0
fact_caching_timeout = 3600

Remember that cached facts can be stale after OS or IP changes.

All Ansible questions Roadmap: Ansible

More on Performance and Scale