# Inventory group variables

**URL:** <https://forum.ansible.com/t/inventory-group-variables/19576>\
**Category:** Ansible Project\
**Created:** [October 21, 2015, 3:48pm UTC](https://forum.ansible.com/t/inventory-group-variables/19576 "2015-10-21T15:48:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wei\_Wei](https://avatars.discourse-cdn.com/v4/letter/w/4da419/32.png) [@Wei\_Wei](https://forum.ansible.com/u/Wei_Wei)\
**Post date:** [October 21, 2015, 3:48pm UTC](https://forum.ansible.com/t/inventory-group-variables/19576/1 "2015-10-21T15:48:01Z")

</div>

Hi,

I am writing an inventory that contains 3 groups of hosts, and each of them have their own host specific variables. It looks like this:

[abc]  
10.10.0.101  
10.10.0.102  
[abc:vars]  
dest\_path=/home/wwwroot/abc  
port=4100  
appname=abc

[efg]  
10.10.0.10  
10.10.0.11  
[efg:vars]  
dest\_path=/home/wwwroot/efg  
port=4100  
appname=efg

[xyz]  
10.10.0.10  
10.10.0.11  
[xyz:vars]  
dest\_path=/home/wwwroot/xyz  
port=3001  
appname=xyz

I run a test playbook, and always get the wrong variables. the playbook looks:

---

<div class="post-metadata">

**Author:** ![CyberCyber](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@CyberCyber](https://forum.ansible.com/u/CyberCyber)\
**Post date:** [October 22, 2015, 1:38am UTC](https://forum.ansible.com/t/inventory-group-variables/19576/2 "2015-10-22T01:38:15Z")

</div>

I’m curious to know what is going wrong here. Setting target\_hosts=efg returns the correct variables, but using abc or xyz still returns the vars of the efg group:

ansible-playbook main.yml -i inventory.txt -e “target\_hosts=abc”

PLAY [abc] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [test vars] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.10.0.101] =\> {  
“msg”: “Group=abc”  
}

TASK: [test vars 2] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.10.0.101] =\> {  
“msg”: “Appname=efg”  
}

TASK: [test vars 3] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.10.0.101] =\> {  
“msg”: “Port=4100”  
}

TASK: [test vars 3] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.10.0.101] =\> {  
“msg”: “Dest\_Path=/home/wwwroot/efg”  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
10.10.0.101 : ok=4 changed=0 unreachable=0 failed=0

I’ve tried splitting the groups vars into their own files under group\_vars, but ended up with same results.

---

<div class="post-metadata">

**Author:** ![Wei\_Wei](https://avatars.discourse-cdn.com/v4/letter/w/4da419/32.png) [@Wei\_Wei](https://forum.ansible.com/u/Wei_Wei)\
**Post date:** [October 22, 2015, 9:03am UTC](https://forum.ansible.com/t/inventory-group-variables/19576/3 "2015-10-22T09:03:46Z")

</div>

Thanks Cyber! Yes, that’s exactly what I am facing.

Anyone any clues?

---

<div class="post-metadata">

**Author:** ![esco\_real](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@esco\_real](https://forum.ansible.com/u/esco_real)\
**Post date:** [October 22, 2015, 9:22am UTC](https://forum.ansible.com/t/inventory-group-variables/19576/4 "2015-10-22T09:22:18Z")

</div>

I get this for abc:

TASK: [test vars] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.10.0.101] =\> {  
“msg”: “abc has name abc and port 4100 and /home/wwwroot/abc”  
}

But the group xyz has the same hosts. So this is a expected result…

Version: 1.9.4
