Interview Prep/Ansible/Inventory and Targeting

Hosts are renamed but keep the same IP, and facts caching still shows old names.

AdvancedScenarioInventory and Targeting
Answer

Situation read → Stale fact cache keyed by inventory_hostname.

What I'd do →

  1. Clear the cache entry: delete the file/key for the old name, or run ansible-playbook ... --flush-cache.
  2. Re-gather facts: ansible renamed -m ansible.builtin.setup.
  3. Reduce fact_caching_timeout where names change often.

Why → The cache key is the inventory name, so renamed hosts leave orphaned entries and new names start empty.

Interview tip → Cached facts speed up playbooks that use gather_facts: smart, but trade freshness.

All Ansible questions Roadmap: Ansible

More on Inventory and Targeting