# Group vars override role vars?

**URL:** <https://forum.ansible.com/t/group-vars-override-role-vars/16956>\
**Category:** Ansible Project\
**Created:** [December 3, 2014, 10:49pm UTC](https://forum.ansible.com/t/group-vars-override-role-vars/16956 "2014-12-03T22:49:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Hughes](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Matt\_Hughes](https://forum.ansible.com/u/Matt_Hughes)\
**Post date:** [December 3, 2014, 10:49pm UTC](https://forum.ansible.com/t/group-vars-override-role-vars/16956/1 "2014-12-03T22:49:21Z")

</div>

I have a role defined with:

`

- hosts: elk  
sudo: true  
vars:  
es\_heap: 8G

`

I run that role against a given inventory that attempts to override that variable:

`  
[elk]  
node1 es\_heap=2G

[elk:vars]  
es\_heap=2G

`

Tried overriding with both host and group vars, but I keep getting the role variable. Aren’t the former supposed to override the latter? I also tried moving the variable from the role in /vars/main.yml, but that had no effect. I must be missing something, because having host variable override role variable seems pretty basic.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 3, 2014, 10:53pm UTC](https://forum.ansible.com/t/group-vars-override-role-vars/16956/2 "2014-12-03T22:53:17Z")

</div>

no, they override the role's defaults/main.yml, but not vars/main.yml

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [December 3, 2014, 10:54pm UTC](https://forum.ansible.com/t/group-vars-override-role-vars/16956/3 "2014-12-03T22:54:17Z")

</div>

Put it into the role's defaults (roles/foo/defaults/main.yml). Those  
are the ones that are really meant to be overridden.

---

<div class="post-metadata">

**Author:** ![Matt\_Hughes](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Matt\_Hughes](https://forum.ansible.com/u/Matt_Hughes)\
**Post date:** [December 3, 2014, 10:55pm UTC](https://forum.ansible.com/t/group-vars-override-role-vars/16956/4 "2014-12-03T22:55:36Z")

</div>

Ah thanks, that makes more sense.

I’m not sure why I’d ever want to use vars/ then. Sure I could be convinced of a use-case, but it seems much more natural for inventory/group/host vars to override anything defined in a role, but I see this discussion has taken place before. 🙂

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 3, 2014, 11:05pm UTC](https://forum.ansible.com/t/group-vars-override-role-vars/16956/5 "2014-12-03T23:05:50Z")

</div>

I use group\_vars a lot and it’s fine to do so.

It is useful for declaring something like a constant though, to save typing, or make things configured in one specific place.

(It keeps configuration of that thing with the playbook vs the inventory)

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [December 3, 2014, 11:08pm UTC](https://forum.ansible.com/t/group-vars-override-role-vars/16956/6 "2014-12-03T23:08:59Z")

</div>

> Iâm not sure why Iâd ever want to use vars/ then. Sure I could be  
> convinced of a use-case

A use case I've seen, which doesn't seem all that uncommon, is when you  
want to use a given role with multiple inventories, each of which has its  
own inventory/group/host vars structure. Putting the default in the role  
lets you have it in one place, and be confident that it's consistent  
across your various inventories unless you explicitly override it.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 3, 2014, 11:36pm UTC](https://forum.ansible.com/t/group-vars-override-role-vars/16956/7 "2014-12-03T23:36:46Z")

</div>

Role variables are definitely a thing.

Where you can move top level playbook things to vars/ or defaults/ in a role it can be a good idea.
