0

In Ansible 2.16.8 on a Mac (M1) running Python 3.12.4 (via homebrew) I am trying to setup a global group_vars/all.yml that can be overwritten by inventory/x/group_vars/all.yml if needed. However, it seems that the global file is overwriting the inventory specific values.

Given the following file:

# group_vars/all.yml
level: global all
# inventory/x/group_vars/all.yml
level: inventory all
# inventory/x/group_vars/test.yml
level: inventory group

And running:

ansible all -i inventory/x -m debug -a "var=level" -o

I get:

test-host | SUCCESS => { "changed": false, "level": "inventory group" }
non-test-host | SUCCESS => { "changed": false, "level": "global all" }

But I am expecting to get:

test-host | SUCCESS => { "changed": false, "level": "inventory group" }
non-test-host | SUCCESS => { "changed": false, "level": "inventory all" }

1 Answer 1

1

Playbook adjacent group_vars precedence over inventory group_vars is expected behavior. Ansible developers consider playbook to be more specific. Consider the example of different plays, overriding the same value, but for different groups.

Move your inventory group_vars/all into any other group's group_vars. Group all is special and a lower priority, for both places you can put group_vars.

Or, do not rely on variable precedence. Use different names for different places a thing is defined, and pick which one in a filter expression.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .