# Ansible 2 group\_vars order

**URL:** <https://forum.ansible.com/t/ansible-2-group-vars-order/21477>\
**Category:** Ansible Project\
**Created:** [May 18, 2016, 2:12pm UTC](https://forum.ansible.com/t/ansible-2-group-vars-order/21477 "2016-05-18T14:12:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![antony.perigault](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@antony.perigault](https://forum.ansible.com/u/antony.perigault)\
**Post date:** [May 18, 2016, 2:12pm UTC](https://forum.ansible.com/t/ansible-2-group-vars-order/21477/1 "2016-05-18T14:12:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 18, 2016, 5:38pm UTC](https://forum.ansible.com/t/ansible-2-group-vars-order/21477/2 "2016-05-18T17:38:15Z")

</div>

Does this help?  
[https://docs.ansible.com/ansible/playbooks\_variables.html#variable-precedence-where-should-i-put-a-variable](https://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)

Johannes

---

<div class="post-metadata">

**Author:** ![antony.perigault](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@antony.perigault](https://forum.ansible.com/u/antony.perigault)\
**Post date:** [May 19, 2016, 7:15am UTC](https://forum.ansible.com/t/ansible-2-group-vars-order/21477/3 "2016-05-19T07:15:44Z")

</div>

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.
