# New 1.2 feature -- group\_vars and host\_vars can now be stored with playbooks

**URL:** <https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892>\
**Category:** Ansible Project\
**Created:** [June 1, 2013, 3:16pm UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892 "2013-06-01T15:16:21Z")\
**Posts on this page:** 11\
**Page:** 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:** [June 1, 2013, 3:16pm UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/1 "2013-06-01T15:16:21Z")

</div>

Small feature added for 1.2

I’ve made it possible to now be able to store group\_vars/ and host\_vars/ directories of variable data alongside playbooks, in addition to requiring them to be in inventory paths.

In fact, both paths can be used at the same time.

If playbook directory files exist, they will “win” over the inventory paths.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [June 3, 2013, 4:38pm UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/2 "2013-06-03T16:38:21Z")

</div>

win as ‘in get loaded’ or as in ovewrite variables?

---

<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:** [June 3, 2013, 4:45pm UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/3 "2013-06-03T16:45:30Z")

</div>

Both will get loaded, I mean they have overwrite priority.

---

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 11, 2013, 1:47pm UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/4 "2013-06-11T13:47:21Z")

</div>

also sprach Michael DeHaan \<michael@ansibleworks.com\> [2013.06.01.1716 +0200]:

> I've made it possible to now be able to store group\_vars/ and host\_vars/  
> directories of variable data alongside playbooks, in addition to requiring  
> them to be in inventory paths.

What is an inventory path? Could you give us a small example,  
please?

---

<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:** [June 12, 2013, 10:45am UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/5 "2013-06-12T10:45:18Z")

</div>

So if your inventory file is /etc/ansible/hosts

The inventory path would be /etc/ansible/

and you could place group\_vars in /etc/ansible/group\_vars

In 1.2, you can also place them alongside the playbook.

---

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 12, 2013, 12:48pm UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/6 "2013-06-12T12:48:21Z")

</div>

also sprach Michael DeHaan \<michael@ansibleworks.com\> [2013.06.12.1245 +0200]:

> So if your inventory file is /etc/ansible/hosts  
> The inventory path would be /etc/ansible/  
> and you could place group\_vars in /etc/ansible/group\_vars  
> In 1.2, you can also place them alongside the playbook.

Thanks for the explanation, unfortunately this does not work with  
v1.1-922-g573d5f6, yet:

fishbowl:…e/ansible|devel|hacking/playbooks% ls -ld ../inventory test.yml group\_vars  
drwx------ 2 madduck madduck 4096 Jun 12 13:06 group\_vars  
-rwx------ 1 madduck madduck 1037 Jun 12 13:07 ../inventory  
-rw------- 1 madduck madduck 139 Jun 12 14:27 test.yml

fishbowl:…e/ansible|devel|hacking/playbooks% cat group\_vars/madduck.net  
foo: group\_vars-madduck.net

fishbowl:…e/ansible|devel|hacking/playbooks% grep msg test.yml  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug: msg=${foo}

fishbowl:…e/ansible|devel|hacking/playbooks% ansible-playbook test.yml | grep msg  
ok: [blue.virt.local] =\> {"msg": "${foo}"}

fishbowl:…e/ansible|devel|hacking/playbooks% mv group\_vars/ ..

fishbowl:…e/ansible|devel|hacking/playbooks% ansible-playbook test.yml | grep msg  
ok: [blue.virt.local] =\> {"msg": "group\_vars-madduck.net"}

---

<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:** [June 12, 2013, 8:29pm UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/7 "2013-06-12T20:29:13Z")

</div>

Nope, it doesn’t work in 1.1, this is a 1.2 feature.

---

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 13, 2013, 6:35am UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/8 "2013-06-13T06:35:38Z")

</div>

also sprach Michael DeHaan \<michael@ansibleworks.com\> [2013.06.12.2229 +0200]:

> Nope, it doesn't work in 1.1, this is a 1.2 feature.

I was using the tip of devel when the v1.2 tag was only a few  
touch-up commits away, so I was basically using 1.2, except the Git  
description mentioned 1.1.

Now I fast-forwarded my tree to v1.2-3-g1fd863c and the behaviour is  
still the same.

I will file an issue.

---

<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:** [June 13, 2013, 11:08am UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/9 "2013-06-13T11:08:13Z")

</div>

It’s tested and does work, let’s have more information.

---

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 13, 2013, 3:08pm UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/10 "2013-06-13T15:08:45Z")

</div>

I thought I already provided that in my first mail, but here it goes  
again, the whole typescript for your viewing pleasure:

% git clone git@github.com:ansible/ansible.git  
[…]

% cd ansible && git describe HEAD  
v1.2-10-g39aa5e5

% . ./hacking/env-setup -q

% echo "[mygroup]\nlocalhost" \> inventory

% mkdir group\_vars && echo "foo: inventory" \> group\_vars/mygroup

% mkdir playbooks && cd playbooks

% mkdir group\_vars && echo "foo: playbooks" \> group\_vars/mygroup

# \$ due to shell  
% cat \<\<\_eof \> test.yml  
- name: debug  
&nbsp;&nbsp;hosts: all  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- debug: msg=\$foo  
\_eof

% ansible-playbook -c local -i ../inventory test.yml | grep 'ok.\*msg'  
ok: [localhost] =\> {"msg": "inventory"}

# \*\*\*\*\*\*\*\* as expected, ../group\_vars/mygroup read (sibling of inventory)

% mv ../group\_vars ../group\_vars.disabled

% ansible-playbook -c local -i ../inventory test.yml | grep 'ok.\*msg'  
ok: [localhost] =\> {"msg": "$foo"}

# \*\*\*\*\*\*\*\* ./group\_vars/mygroup not read (sibling of playbook)

Did I misunderstand?

---

<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:** [June 13, 2013, 3:22pm UTC](https://forum.ansible.com/t/new-1-2-feature-group-vars-and-host-vars-can-now-be-stored-with-playbooks/12892/11 "2013-06-13T15:22:56Z")

</div>

Can you show this as a gist instead, or something that shows the structure?
