ansible2.4: playbook group_vars/* no longer loaded into hostvars

Hi,

upgrade-ing to Ansible 2.4, I have noticed that variables defined in ‘group_vars/all.yaml’, ‘group_vars/groupX.yaml’ no longer appear in ‘hostvars’. I’m talking about referencing hostvars of another host from currently executing one.

I have the following directory structure:

.
├── env
│ ├── dev
│ │ ├── group_vars
│ │ │ └── all.yaml
│ │ └── inventory
│ └── prod
│ ├── group_vars
│ │ └── all.yaml
│ └── inventory
├── group_vars
│ └── all.yaml
└── site.yaml

Only the variables defined at “inventory” level group_vars propagate to hostvars. This behavior has changed between 2.3-2.4.

In Ansible 2.3, if I needed a variable in hostvars to be define for all environments, I would put it to ‘group_vars/all.yaml’. Now I have to duplicate it to all inventory’s group_vars, which is … suboptimal.

Q: is there any place (in Ansible2.4) where you could define “inventory variable defaults”, common for all environments/inventories ??

Regards,

BranoZ

I see this behavior too (in 2.4.1). On searching, one tends to find a lot of “Ansible used to resolve group_vars and host_vars from the current directory; now it doesn’t; don’t do that”. But that isn’t my problem, or yours I wager.

My suspicion is that it seems to be a problem with playbook-adjacent (group|host)_vars files that only is seen when specifying a inventory directory (additionally, possibly, specifying inventory files in a subdirectory). Single inventory files often tend to be in the same directory as playbooks, so it muddies the water sometimes when testing this. It almost seems like ever since support was added for (group|host)_vars files adjacent to inventory, the playbook-adjacent setup is not tested as much (despite the best practices page and other documentation).

see if this if fixed in the upcoming 2.4.2, I believe this
https://github.com/ansible/ansible/pull/32269 PR solves the corner
cases that prevented play adjacent group/host vars from being picked
up