Invalid group priority.

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:

In any section, overriding var will overwrite the previous instance. If several groups have the same variable, the last loaded one wins. If you define a variable twice in the "Games vars:" section, the second wins.

Does this mean that the boot order is alphabetical and abc.yml has the lowest priority, while xyz.yml is the highest, or does it depend on the order of the groups in hosts ?

What is the boot order?


Interestingly, changing the order of groups in hosts also changes the results, but in an unpredictable way.

I tried running ansible-playbook my_var.yml -c local (which returns the value of a variable) with all the combinations:

 [all] localhost [xyz] localhost [abc] localhost 

but I still canโ€™t understand how this works.

+7
variables order ansible
source share
2 answers

I would say that Ansible behavior is not specified in this case.

0
source share

It looks like the following issue from the Ansible git repository may have examined the behavior you described: Invalid group_vars from inventory do not support repeated hosts

Looking at code changes from a related commit, it seems that now the groups should sort by depth and then by name (in alphabetical order).

It is worth noting that this behavior is likely to change depending on which version of Ansible you are using, since these changes were only integrated in stable-2.2 in the Ansible repository.

0
source share

All Articles