DevOps / Ansible Interview questions
How does Ansible implement fact caching internally?
Fact caching stores the ansible_facts dictionary gathered for each host in an external cache backend, keyed by hostname, with a configurable time-to-live, so a future run can read cached facts instead of re-running the setup module.
# ansible.cfg [defaults] fact_caching = redis fact_caching_connection = localhost:6379:0 fact_caching_timeout = 86400
Supported backends include a simple jsonfile (facts written to local disk as JSON), redis, and other plugin-based options, chosen based on whether facts need to be shared across multiple control nodes (favoring a networked backend like Redis) or just persisted locally between runs (where jsonfile is simpler). On each play, Ansible checks whether a valid, non-expired cache entry exists for a given host; if so, it loads facts from there instead of dispatching setup, and if not (or if the entry expired past fact_caching_timeout), it gathers fresh facts and writes the result back to the cache for next time.
More Related questions...