# Improved ways to store host and group variables

**URL:** <https://forum.ansible.com/t/improved-ways-to-store-host-and-group-variables/11710>\
**Category:** Ansible Project\
**Created:** [July 21, 2012, 12:12pm UTC](https://forum.ansible.com/t/improved-ways-to-store-host-and-group-variables/11710 "2012-07-21T12:12:02Z")\
**Posts on this page:** 6\
**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:** [July 21, 2012, 12:12pm UTC](https://forum.ansible.com/t/improved-ways-to-store-host-and-group-variables/11710/1 "2012-07-21T12:12:02Z")

</div>

New minor feature.

I really wanted to be able to store structured group and host variables separate from my inventory.

Assume your inventory file is /etc/ansible/hosts and looks like this:

===== START =====  
[webservers]  
pinky  
brain

[dbservers]  
pinky  
snowball  
===== STOP =====

With this new feature, for the host Pinky, ansible will load variables from these places, in order:

&nbsp;&nbsp;&nbsp;&nbsp;/etc/ansible/group\_vars/webservers  
&nbsp;&nbsp;&nbsp;&nbsp;/etc/ansible/group\_vars/dbservers  
&nbsp;&nbsp;&nbsp;&nbsp;/etc/ansible/host\_vars/pinky

If these files don't exist, nothing happens.  
If your host file was in a different location, the path would still be relative to that file, so it still works for non-root/checkout users

(This is also, incidentally, how I'm going to enable removal of the YAML inventory format. We'll auto-convert any variables stored into an inventory  
file into this structure.)

So yeah, with this, you can totally happily use the INI file format to describe your hosts and groups -- because it's a lot simpler -- and then if you  
need for store a hash or a list or something in a group or host variable, you have a very easy way to do that.

Will include this in the docs section when 0.6 rolls out, but it's available on the development branch now.

--Michael

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [July 21, 2012, 12:47pm UTC](https://forum.ansible.com/t/improved-ways-to-store-host-and-group-variables/11710/2 "2012-07-21T12:47:38Z")

</div>

> With this new feature, for the host Pinky, ansible will load variables from these places, in order:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;/etc/ansible/group\_vars/webservers  
> &nbsp;&nbsp;&nbsp;&nbsp;/etc/ansible/group\_vars/dbservers  
> &nbsp;&nbsp;&nbsp;&nbsp;/etc/ansible/host\_vars/pinky

Way cool!

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

---

<div class="post-metadata">

**Author:** ![John\_Callender](https://avatars.discourse-cdn.com/v4/letter/j/b5ac83/32.png) [@John\_Callender](https://forum.ansible.com/u/John_Callender)\
**Post date:** [July 21, 2012, 5:04pm UTC](https://forum.ansible.com/t/improved-ways-to-store-host-and-group-variables/11710/3 "2012-07-21T17:04:35Z")

</div>

What format are the group\_vars/\* and host\_vars/\* files in? Are those YAML?

---

<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:** [July 21, 2012, 5:40pm UTC](https://forum.ansible.com/t/improved-ways-to-store-host-and-group-variables/11710/4 "2012-07-21T17:40:03Z")

</div>

Yep.

---

<div class="post-metadata">

**Author:** ![CWS](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@CWS](https://forum.ansible.com/u/CWS)\
**Post date:** [July 22, 2012, 7:35am UTC](https://forum.ansible.com/t/improved-ways-to-store-host-and-group-variables/11710/5 "2012-07-22T07:35:37Z")

</div>

Hmm. With a hosts file like this:

---

<div class="post-metadata">

**Author:** ![CWS](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@CWS](https://forum.ansible.com/u/CWS)\
**Post date:** [July 22, 2012, 7:57am UTC](https://forum.ansible.com/t/improved-ways-to-store-host-and-group-variables/11710/6 "2012-07-22T07:57:56Z")

</div>

PS: Removing the ‘if’ condition in playbook/ **init**.py has the group\_vars file working as expected for task actions (bar untested side effects), but the variables are not used in the task names. If I change the playbook to
