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.
More on Variables, Facts and Precedence Problems
Variables in `group_vars/webservers.yml` are silently ignoredBeginnerYou set `nginx_port: 8443` in inventory `group_vars`, but the role still uses `80`Intermediate`set_fact: release_tag=v2` runs, but later tasks still see `v1`Intermediate`'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'` when templating `hostvars['db01']`Intermediate`'ansible_eth0' is undefined` on new cloud instancesBeginnerFacts like `ansible_hostname` became undefined after someone changed `ansible.cfg`Intermediate