Ansible 2 group_vars order

Hello,

I do many tests and I don’t understand the group_vars load order in ansible 2. With ansible 1 vars are load in my playbook order. But with ansible 2 it seems to be totally random.

For example:

I have 2 groups:

group_vars# tree
├── all.yml
├── site_plo.yml

toto: foo
└── machine_ehp.yml

toto: bar

I place my machine in thats groups with this playbook :

  • name: Dynamically define site
    group_by: “key=site_{{ inventory_hostname_short[0:3] }}”

  • name: Dynamically define environment
    group_by: “key=machine_{{ inventory_hostname_short[3:6] }}”

  • debug: var=toto

In this configuration toto=foo

When I rename machine_eh1 there is no logic :
amachine_eh1: toto=bar
bmachine_eh1: toto=bar
cmachine_eh1: toto=bar
dmachine_eh1: toto=foo
emachine_eh1: toto=bar
zmachine_eh1: toto=foo

There is a bug ? a specific order rule ? a random rule ?

Thanks for your help

Does this help?
https://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

Johannes

My question is about this part of doc:

If multiple groups have the same variable, the last one loaded wins

What is the load order ? It seems to not be alphabetical.