Interview Prep/Ansible/Variables, Facts and Precedence Problems

`host_vars/web01.yml` is ignored for one host

BeginnerTroubleshootingVariables, Facts and Precedence Problems
Answer

Likely causes → The host's inventory name is web01.example.com (or an IP address), and the host_vars filename has to match the inventory hostname exactly, not ansible_host or the short name.

Diagnose → ansible-inventory --list | jq '._meta.hostvars | keys'

Fix → Rename the file to host_vars/web01.example.com.yml, or change the inventory to use a short alias with ansible_host set:

web01 ansible_host=web01.example.com

Prevent → Use short, stable aliases as inventory names, and keep FQDNs and IPs in ansible_host.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence Problems