# using group\_vars with an inventory plugin?

**URL:** <https://forum.ansible.com/t/using-group-vars-with-an-inventory-plugin/11870>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [September 7, 2012, 3:15pm UTC](https://forum.ansible.com/t/using-group-vars-with-an-inventory-plugin/11870 "2012-09-07T15:15:26Z")\
**Posts on this page:** 8\
**Page:** 1

<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:** [September 7, 2012, 3:15pm UTC](https://forum.ansible.com/t/using-group-vars-with-an-inventory-plugin/11870/1 "2012-09-07T15:15:26Z")

</div>

Just put your group\_vars directory in the same directory as the  
inventory script.

./ec2.py  
./group\_vars/\<name\_of\_group\>  
./group\_vars/\<name\_of\_other\_group\>

(Do not add a ".yml" extension on the name of the group)

---

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [May 28, 2013, 8:22pm UTC](https://forum.ansible.com/t/using-group-vars-with-an-inventory-plugin/11870/2 "2013-05-28T20:22:56Z")

</div>

I’m having trouble exposing group\_vars on an end node that is part of a group defined by an ec2 instance tag.

from inside my ‘staging’ directory:

[david@ops-1 staging{master}]$ ls

ansible.cfg inventory

[david@ops-1 staging{master}]$ cat ansible.cfg  
[defaults]  
hostfile = inventory/ec2.py

inventory directory contains another sub directory: groups\_vars which contains: tag\_mogilefsd\_1

i can prove that a node matches on that group:

david@ops-1 staging{master}]$ ansible -m ping tag\_mogilefsd\_1  
10.100.1.45 | success \>\> {  
“changed”: false,  
“ping”: “pong”  
}

and yet using the setup module to dump variables on the end node, i don’t see the contents of inventory/group\_vars/tag\_mogilefsd\_1

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 29, 2013, 12:45am UTC](https://forum.ansible.com/t/using-group-vars-with-an-inventory-plugin/11870/3 "2013-05-29T00:45:57Z")

</div>

Hmm,

There should be nothing here that is ec2 specific.

Can you show me the output of “tree” on your inventory directory just so I can see everything?

Also can you tell me what version of ansible you are using? Older versions did not load group\_vars/host\_vars into “ad-hoc” /usr/bin/ansible and only worked in playbooks.

My other thought is maybe there’s an error in your group\_vars file.

---

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [May 29, 2013, 1:51am UTC](https://forum.ansible.com/t/using-group-vars-with-an-inventory-plugin/11870/4 "2013-05-29T01:51:18Z")

</div>

> Hmm,
> 
> There should be nothing here that is ec2 specific.
> 
> Can you show me the output of “tree” on your inventory directory just so I can see everything?

[https://gist.github.com/davidbirdsong/5667411](https://gist.github.com/davidbirdsong/5667411)

> Also can you tell me what version of ansible you are using? Older versions did not load group\_vars/host\_vars into “ad-hoc” /usr/bin/ansible and only worked in playbooks.

I call it ansible-1.2 for rpm building-sake:

[david@ops-1 ansible{devel}]$ git log -n 1 --format=format:%H  
753ebea186d93f5f26ec394bd6ec3fbdca43e2d5

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 29, 2013, 1:52am UTC](https://forum.ansible.com/t/using-group-vars-with-an-inventory-plugin/11870/5 "2013-05-29T01:52:42Z")

</div>

Can you show me what you are using to get the value of master\_db\_server out?

Maybe it’s something subtle in there instead?

---

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [May 29, 2013, 1:58am UTC](https://forum.ansible.com/t/using-group-vars-with-an-inventory-plugin/11870/6 "2013-05-29T01:58:27Z")

</div>

> Can you show me what you are using to get the value of master\_db\_server out?
> 
> Maybe it’s something subtle in there instead?

[david@ops-1 staging{master}]$ ansible -m setup tag\_mogilefsd\_1 | grep -i master  
[david@ops-1 staging{master}]$

am i doing it wrong?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 29, 2013, 2:07am UTC](https://forum.ansible.com/t/using-group-vars-with-an-inventory-plugin/11870/7 "2013-05-29T02:07:57Z")

</div>

Oh that.

Yes.

The setup module returns facts that ansible discovered (built in stuff), but it doesn’t return variables you have set.

Create a playbook and try the ‘debug’ module or use the ‘template’ module and {{ varname }} and you should see it fine.

---

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [May 29, 2013, 6:05am UTC](https://forum.ansible.com/t/using-group-vars-with-an-inventory-plugin/11870/8 "2013-05-29T06:05:14Z")

</div>

> Oh that.
> 
> Yes.
> 
> The setup module returns facts that ansible discovered (built in stuff), but it doesn’t return variables you have set.
> 
> Create a playbook and try the ‘debug’ module or use the ‘template’ module and {{ varname }} and you should see it fine.

yep, that was it.

great, thanks for the clarification and reminding me to use the debug module. it should come in handy.
