Feature request --show-vars-path?

The location of the group_vars and host_vars directories has a tendency to bite me and my team.

We recently moved to using vagrant/virtualbox and vagrant/fusion for testing and we specify a playbook like this:

config.vm.provision “ansible”, type: “ansible” do |ansible|
config.ssh.username = “vagrant”
config.ssh.forward_agent = true
config.ssh.insert_key = false
ansible.playbook = “…/playbooks/dns-server.yml”
end

A tree of my directory layout.

.
├── ansible
├── bin
├── include
├── lib
├── man
├── playbooks
└── vagrant

If I’m in the vagrant directory and given the ansible.playbook above (“…/playbooks/dns-server.yml”) where does ansible look for the group_vars and host_vars directories?

Here?

vagrant/group_vars
vagrant/host_vars

Here?

playbooks/group_vars
playbooks/host_vars

Can the path for the “vars” be set explicitly? Or a set of directories be appended to the system defaults?

I would find an “ansible --show-vars-path” extremely helpful.

I think I’m missing something simple. Could someone point me to the documentation that explains how ansible searches for the group_vars and host_vars directories?

Thanks.

http://docs.ansible.com/ansible/intro_inventory.html

Tip: In Ansible 1.2 or later the group_vars/ and host_vars/ directories can exist in either the playbook directory OR the inventory directory. If both paths exist, variables in the playbook directory will override variables set in the inventory directory.

or just strace?

example:

strace ansible -m debug all 2>&1 | grep _vars

esco

It will look first to the inventory adjacent group/host_vars and then
to the play adjacent group/host_vars.

Not sure how vagrant/ fits into this picture.

I feel the pain, and was in fact just now wishing for explicit path variables to set them. As the others mentioned, the group/host_vars can be relative to either inventory or playbook - I don’t want to place them relative to playbooks at present.

I originally had a static inventory file, but that bit me, because hosts wouldn’t always be up but ansible was trying to iterate whatever was in groups.

The setup I’ve currently got is, using the provisioner…

$ tree inv
inv
├── dev_aws
│ ├── ec2.ini
│ ├── ec2.py
│ ├── group_vars → …/group_vars
│ ├── host_vars → …/host_vars
│ └── hosts
├── dev_vagrant
│ ├── group_vars → …/group_vars
│ ├── host_vars → …/host_vars
│ └── hosts → …/…/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory

and

$ tree .vagrant

└── provisioners
└── ansible
└── inventory
├── group_vars → …/…/…/…/inv/group_vars
├── host_vars → …/…/…/…/inv/host_vars

the symlinks are all in my git repo.

hope that gives some idea towards a solution.

Hi,

I have written a small PR that add the capability to Ansible to add directories in current context. You can have a look here: https://github.com/ansible/ansible/pull/12628

Basically, you get a new --parent-inventory option (or -p for short version) that let you specify additional group/host_vars directories (the option append each directories specified).

Maybe we can add this options you are talking about (–show-vars-path and something like --set-vars-path).

Regards,

Yannig