# group vars ?

**URL:** <https://forum.ansible.com/t/group-vars/11825>\
**Category:** Ansible Project\
**Created:** [August 24, 2012, 9:24am UTC](https://forum.ansible.com/t/group-vars/11825 "2012-08-24T09:24:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [August 24, 2012, 9:24am UTC](https://forum.ansible.com/t/group-vars/11825/1 "2012-08-24T09:24:17Z")

</div>

Wondering the variables could have been assigned per group, right.  
If i reuse the variable of same name they are overwritten within the  
hosts file or with global\_vars now ?

hosts:

[group1]  
10.100.1.100

[group2]  
10.100.1.100

[group1:vars]  
username=value1

[group2:vars]  
username=value2

The playbook will give me result 'value2' now, also tried with --extra-  
vars="groups=group1"

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 24, 2012, 1:19pm UTC](https://forum.ansible.com/t/group-vars/11825/2 "2012-08-24T13:19:15Z")

</div>

> Wondering the variables could have been assigned per group, right.  
> If i reuse the variable of same name they are overwritten within the  
> hosts file or with global\_vars now ?

The “group\_vars” files definitely resolve in tree order, where a group name can override all. This may not be currently true for [group:vars] inline.

hosts should override groups.

> hosts:
> 
> [group1]  
> 10.100.1.100
> 
> [group2]  
> 10.100.1.100
> 
> [group1:vars]  
> username=value1
> 
> [group2:vars]  
> username=value2
> 
> The playbook will give me result ‘value2’ now, also tried with --extra-  
> vars=“groups=group1”

Not sure how that part about extra vars is relevant if you don’t had a variable $groups in your “hosts:” directive, it’s pretty meaningless.  
In fact, you probably shouldn’t set this at all, as the variable “groups” is typically useful to Ansible. “hosts” maybe

> * * *
> 
> - name: test  
> hosts: group1

hosts: $hosts
