New 1.2 feature -- group_vars and host_vars can now be stored with playbooks

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.

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

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

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?

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.

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
      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"}

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

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.

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

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
  hosts: all
  tasks:
    - 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?

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