Interview Prep/Ansible/Variables, Facts and Precedence Problems

With `gather_facts: false`, a template renders the host's old IP address from last week

AdvancedTroubleshootingVariables, Facts and Precedence Problems
Answer

Likely causes → Fact caching is on (fact_caching = jsonfile or redis) with a long fact_caching_timeout. The host was rebuilt, but the cache still serves the old facts. set_fact: ... cacheable: true values also persist across runs.

Diagnose →

ansible-config dump --only-changed | grep -i fact_caching
ls -l ~/.ansible/fact_cache/web01   # jsonfile backend

Fix → Run once with --flush-cache, or delete that host's cache entry. Then gather fresh facts with ansible.builtin.setup for rebuilt hosts.

Prevent → Set a sensible fact_caching_timeout (for example 3600–86400 seconds). In immutable or auto-scaled fleets, prefer gathering = smart with a short timeout, and use cacheable only for values that are safe to keep.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence Problems