# group\_vars precedence?

**URL:** <https://forum.ansible.com/t/group-vars-precedence/19097>\
**Category:** Ansible Project\
**Created:** [August 24, 2015, 5:12pm UTC](https://forum.ansible.com/t/group-vars-precedence/19097 "2015-08-24T17:12:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Duncan\_Hutty](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@Duncan\_Hutty](https://forum.ansible.com/u/Duncan_Hutty)\
**Post date:** [August 24, 2015, 5:12pm UTC](https://forum.ansible.com/t/group-vars-precedence/19097/1 "2015-08-24T17:12:49Z")

</div>

I have a host that is a member of 2 groups. Both groups set a variable 'my\_var' in `group_vars/\<group_name\>/`. How do I predict which one wins? (Ansible-1.9.2)

With this playbook:

---

<div class="post-metadata">

**Author:** ![Bill\_Wiens](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@Bill\_Wiens](https://forum.ansible.com/u/Bill_Wiens)\
**Post date:** [January 19, 2016, 9:40pm UTC](https://forum.ansible.com/t/group-vars-precedence/19097/2 "2016-01-19T21:40:45Z")

</div>

Did you ever find out how this works? I have a variable that’s set in both group\_vars/aws/secrets.yml and group\_vars/aws\_dogfood/secrets.yml, and I can’t figure out why on some servers it uses the variable from “aws” and others use the variable from “aws\_dogfood”.

-Bill

---

<div class="post-metadata">

**Author:** ![Duncan\_Hutty](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@Duncan\_Hutty](https://forum.ansible.com/u/Duncan_Hutty)\
**Post date:** [January 20, 2016, 2:42pm UTC](https://forum.ansible.com/t/group-vars-precedence/19097/3 "2016-01-20T14:42:39Z")

</div>

The short answer is 'no', sorry.

But you've brought this back to my mind and hopefully I'll have a chance to find out. If you do, I'd love to hear it.

I suspect the behaviour is actually 'undefined' because in python, dicts are not ordered, but I'm not sure. Perhaps we could convince Ansible that this matters and to replace the relevant dict with an collections.OrderedDict and insert key/value pairs in a specific (lexicographic?) order.

In Ansible 2.0+, it's probably somewhere in the VariableManager class (lib/ansible/vars/\_\_init\_\_.py)
