Interview Prep/Ansible/Variables, Facts and Precedence

How does fact caching work and how do you configure it?

AdvancedConceptVariables, Facts and Precedence
Answer

Fact caching saves gathered facts between runs so Ansible can skip the setup step for hosts whose facts are still fresh.

[defaults]
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /var/cache/ansible/facts
fact_caching_timeout = 86400

gathering = smart gathers only when there is no cached entry. Cache plugins include jsonfile, redis and memcached. Redis suits shared AWX/CI runners. Risks: stale facts after an OS upgrade or IP change, and sensitive data stored in the cache, so protect the directory or the Redis instance.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence