# group\_vars/\* and inventory script (and vars vars vars)

**URL:** <https://forum.ansible.com/t/group-vars-and-inventory-script-and-vars-vars-vars/12490>\
**Category:** Ansible Project\
**Created:** [March 12, 2013, 10:42pm UTC](https://forum.ansible.com/t/group-vars-and-inventory-script-and-vars-vars-vars/12490 "2013-03-12T22:42:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maykel\_Moya](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Maykel\_Moya](https://forum.ansible.com/u/Maykel_Moya)\
**Post date:** [March 12, 2013, 10:42pm UTC](https://forum.ansible.com/t/group-vars-and-inventory-script-and-vars-vars-vars/12490/1 "2013-03-12T22:42:50Z")

</div>

Hello ansiblers

When using an inventory file I can define vars in group\_vars/{groupname,hostname} and they are loaded automatically but when using an inventory script this doesn't work. Some question:

- Is this intended behaviour?  
- If so, any hint to get an equivalent of inventory\_script+group\_vars behaviour?

I could hack the inventory script to load things from group\_vars/\* but the groups a host belongs to are not available when the inventory is called for '--host foo' so I could load any group\_vars/$hostname but not a group\_vars/$groupname (at least the inventory is reparsed at '--host' time to find outs current groups for given host).

Is this inventory\_script + static groups\_vars nonsense/crazy?

The behaviour I'm trying to get from Ansible is:  
- look if a var is defined for a host  
- if not, look if defined for a group  
- if not, look if defined in defaults  
- if not, no such var

vars\_file: [$group.yml, default.yml] would work but then host vars from inventory script will be ignored because of precedence rules.

groups\_vars/groupname would work but group\_vars are ignored when using an inventory\_script.

having both default\_\<varname\> and \<varname\> and filling templates with {% if defined \<varname\> %} something with \<varname\> {% else %} something with default\_\<varname\> {% endif %} would work but this is ugly as hell.

So... thanks for your help/recommendations/criticisms.

Regards,  
maykel

---

<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:** [March 13, 2013, 1:14am UTC](https://forum.ansible.com/t/group-vars-and-inventory-script-and-vars-vars-vars/12490/2 "2013-03-13T01:14:46Z")

</div>

ansible --version?

---

<div class="post-metadata">

**Author:** ![Maykel\_Moya](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Maykel\_Moya](https://forum.ansible.com/u/Maykel_Moya)\
**Post date:** [March 13, 2013, 12:21pm UTC](https://forum.ansible.com/t/group-vars-and-inventory-script-and-vars-vars-vars/12490/3 "2013-03-13T12:21:35Z")

</div>

ansible-playbook 1.1 (devel 0c80c76833) last updated 2013/03/13 12:23:21 (GMT +200)

Thanks,  
maykel

---

<div class="post-metadata">

**Author:** ![Maykel\_Moya](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Maykel\_Moya](https://forum.ansible.com/u/Maykel_Moya)\
**Post date:** [March 13, 2013, 12:45pm UTC](https://forum.ansible.com/t/group-vars-and-inventory-script-and-vars-vars-vars/12490/4 "2013-03-13T12:45:08Z")

</div>

[self-response thanks to dhozac]

I missed the 'relative to the inventory file' part in [1] and had the group\_vars/ dir relative to the playbook instead of the inventory script.

It's working now as expected with:  
- inventory\_script  
- groups\_var/\<groupname\>  
- groups\_var/all

Sorry for the noise.

Regards,  
maykel

[1] [http://ansible.cc/docs/patterns.html#splitting-out-host-and-group-specific-data](http://ansible.cc/docs/patterns.html#splitting-out-host-and-group-specific-data)
