Interview Prep/Ansible/Inventory and Targeting

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 →

  1. Remember: group_vars/ is searched next to the inventory file and next to the playbook.
  2. If the inventory is a plugin config in inventories/prod/aws_ec2.yml, put group_vars/ in inventories/prod/.
  3. 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.

All Ansible questions Roadmap: Ansible

More on Inventory and Targeting