How do you reduce the cost of fact gathering?
IntermediateProductionPerformance and Scale
Answer
gather_facts: falseon plays that do not use facts.gather_subset: [min, network](or!hardware) to avoid slow hardware probes.- Fact caching with
gathering = smartand ajsonfileor Redis cache, so unchanged hosts skip the setup module. - Use
gather_facts: falseand then a single earlysetupfor 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.
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?BeginnerWhat is Mitogen for Ansible and would you use it?Advanced