# Path to group\_vars etc. when inventory is a directory

**URL:** <https://forum.ansible.com/t/path-to-group-vars-etc-when-inventory-is-a-directory/13631>\
**Category:** Ansible Project\
**Created:** [October 8, 2013, 3:54pm UTC](https://forum.ansible.com/t/path-to-group-vars-etc-when-inventory-is-a-directory/13631 "2013-10-08T15:54:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grzegorz\_Nosek](https://avatars.discourse-cdn.com/v4/letter/g/5daacb/32.png) [@Grzegorz\_Nosek](https://forum.ansible.com/u/Grzegorz_Nosek)\
**Post date:** [October 8, 2013, 3:54pm UTC](https://forum.ansible.com/t/path-to-group-vars-etc-when-inventory-is-a-directory/13631/1 "2013-10-08T15:54:51Z")

</div>

Hi,

I have the following setup:

.../group\_vars/all.yml etc  
.../hosts/static \<- an ini file  
.../hosts/database \<- a script

ansible-playbook -i .../hosts (v1.2, didn't try 1.3 yet in this scenario) fails to find the group\_vars directory, because it looks for .../hosts/group\_vars/ instead. I understand this is consistent with the rule "look in the directory containing the hosts file" but is this really the desired behaviour? Shouldn't the rule be "directory containing whatever the user specified as inventory"? Would be much more straightforward IMHO.

Best regards,  
&nbsp;&nbsp;Grzegorz Nosek

---

<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:** [October 8, 2013, 3:56pm UTC](https://forum.ansible.com/t/path-to-group-vars-etc-when-inventory-is-a-directory/13631/2 "2013-10-08T15:56:26Z")

</div>

Yep, this is intended behavior as this allows you to individually select inventory inside the directory or the whole of all of them without moving your group\_vars and host\_vars files.

---

<div class="post-metadata">

**Author:** ![Grzegorz\_Nosek](https://avatars.discourse-cdn.com/v4/letter/g/5daacb/32.png) [@Grzegorz\_Nosek](https://forum.ansible.com/u/Grzegorz_Nosek)\
**Post date:** [October 8, 2013, 4:08pm UTC](https://forum.ansible.com/t/path-to-group-vars-etc-when-inventory-is-a-directory/13631/3 "2013-10-08T16:08:05Z")

</div>

Hmm, OK.

So when I migrate from a single-file inventory to a split one, my paths change from:

…/hosts  
…/host\_vars/

to:

…/hosts/file\_a  
…/hosts/file\_b  
…/hosts/host\_vars/

right?

How do I prevent Ansible from trying to load contents of host\_vars as inventory files?

Best regards,  
Grzegorz Nosek

W dniu wtorek, 8 października 2013 17:56:26 UTC+2 użytkownik Michael DeHaan napisał:

---

<div class="post-metadata">

**Author:** ![Grzegorz\_Nosek](https://avatars.discourse-cdn.com/v4/letter/g/5daacb/32.png) [@Grzegorz\_Nosek](https://forum.ansible.com/u/Grzegorz_Nosek)\
**Post date:** [October 8, 2013, 5:34pm UTC](https://forum.ansible.com/t/path-to-group-vars-etc-when-inventory-is-a-directory/13631/4 "2013-10-08T17:34:12Z")

</div>

In case somebody else wonders, Ansible does that out of the box:

if i.endswith(“~”) or i.endswith(“.orig”) or i.endswith(“.bak”):  
continue  
if i.endswith(“.ini”):

# configuration file for an inventory script

continue  
if i.endswith(“.retry”):

# this file is generated on a failed playbook and should only be

# used when run specifically

continue

# Skip hidden files

if i.startswith(‘.’) and not i.startswith(‘./’):  
continue

# These are things inside of an inventory basedir

if i in (“host\_vars”, “group\_vars”, “vars\_plugins”):  
continue

Best regards,  
Grzegorz Nosek

---

<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:** [October 9, 2013, 12:10am UTC](https://forum.ansible.com/t/path-to-group-vars-etc-when-inventory-is-a-directory/13631/5 "2013-10-09T00:10:32Z")

</div>

“How do I prevent Ansible from trying to load contents of host\_vars as inventory files?”

Shouldn’t be doing that. If you can share steps to reproduce please file a github ticket and I’ll take a look.
