Let's say I have 3 files in group_vars:
abc.yml
all.yml
xyz.yml
And the same variable defined in them:
- my_var: abc
- my_var: all
- my_var: xyz
Ansible documentation says:
Within any section, redefining a var will overwrite the previous instance. If multiple groups have the same variable, the last one loaded wins. If you define a variable twice in a play’s vars: section, the 2nd one wins.
Does it mean that load order is alphabetical one and abc.yml
has the lowest priority, whereas xyz.yml
the highest, or it depends on order of groups in hosts
?
What is the loading order?
It is interesting, that changing the order of groups in hosts
changes results as well, but in unpredictable way.
I tried running ansible-playbook my_var.yml -c local
(that only returns variable value) with all the combinations of:
[all]
localhost
[xyz]
localhost
[abc]
localhost
but I still cannot figure out how it works.