Interview Prep/Ansible/Variables, Facts and Precedence Problems

Variables in `group_vars/webservers.yml` are silently ignored

BeginnerTroubleshootingVariables, Facts and Precedence Problems
Answer

Likely causes → Ansible only loads group_vars/ and host_vars/ from two places: next to the inventory source and next to the playbook. A group_vars/ folder anywhere else (repo root, roles/) is not read. A filename that does not match the group name exactly (webserver.yml against group webservers) is also skipped.

Diagnose →

ansible-inventory -i inventories/prod/hosts.yml --host web01 --vars
ansible-inventory -i inventories/prod/hosts.yml --graph

If the variable is not shown, Ansible never loaded it.

Fix → Move the folder to inventories/prod/group_vars/webservers.yml, or next to the playbook. Make the filename match the group name.

Prevent → Use the standard layout of one inventory directory per environment, each with its own group_vars/ and host_vars/.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence Problems