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.
More on Variables, Facts and Precedence
Where can you define variables in Ansible?BeginnerHow do you reference a variable, and when must you quote it?BeginnerGive a summary of variable precedence.IntermediateWhat are the lowest and highest precedence sources, and why does that matter?IntermediateWhat is the difference between a role's `defaults/` and `vars/`?IntermediateWhat are facts and how are they gathered?Beginner