Your inventory plugin returns hosts, but variables from `group_vars` next to the playbook are ignored.
AdvancedScenarioInventory and Targeting
Answer
Situation read → group_vars are loaded relative to the inventory source or to the playbook, and the location matters.
What I'd do →
- Remember:
group_vars/is searched next to the inventory file and next to the playbook. - If the inventory is a plugin config in
inventories/prod/aws_ec2.yml, putgroup_vars/ininventories/prod/. - Check with
ansible-inventory -i inventories/prod --host <h>.
Why → Playbook-adjacent group_vars load for any inventory; inventory-adjacent ones load only for that inventory's directory.
Interview tip → When both exist, playbook-adjacent group_vars win over inventory-adjacent ones.
More on Inventory and Targeting
You are handed a fresh Ansible project and 10 servers. How do you make sure Ansible can reach all of them before writing any playbook?BeginnerYour team keeps prod and staging hosts in one inventory file and someone ran a playbook on prod by mistake. How do you prevent it?IntermediateYou need to run a playbook on only the web servers in Mumbai that are not in the canary group. How?BeginnerServers are autoscaled in AWS and IPs change daily. How do you keep the inventory accurate?IntermediateA host is reachable by SSH on port 2222 with a different user from all others. How do you model that?BeginnerYou must configure servers in a private subnet that is only reachable through a bastion.Intermediate