# Host\_vars not discovered

**URL:** <https://forum.ansible.com/t/host-vars-not-discovered/46042>\
**Category:** Get Help\
**Tags:** inventory\
**Created:** [July 13, 2026, 7:58am UTC](https://forum.ansible.com/t/host-vars-not-discovered/46042 "2026-07-13T07:58:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aragilar](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/aragilar/32/8642_2.png) [@aragilar](https://forum.ansible.com/u/aragilar)\
**Post date:** [July 13, 2026, 7:58am UTC](https://forum.ansible.com/t/host-vars-not-discovered/46042/1 "2026-07-13T07:58:51Z")

</div>

Hi I’ve followed [Sample Ansible setup — Ansible Community Documentation](https://docs.ansible.com/projects/ansible/latest/tips_tricks/sample_setup.html#alternative-directory-layout) and sometimes the `host_vars` directories are not discovered. How do I debug this, and does this layout work?

---

<div class="post-metadata">

**Author:** ![bvitnik](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bvitnik/32/4132_2.png) [@bvitnik](https://forum.ansible.com/u/bvitnik)\
**Post date:** [July 13, 2026, 11:15am UTC](https://forum.ansible.com/t/host-vars-not-discovered/46042/2 "2026-07-13T11:15:08Z")

</div>

> [@aragilar](#):
>
> does this layout work?

Yes.

> [@aragilar](#):
>
> How do I debug this

By providing us with the reproducible example of what does not work 🙂.

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [July 13, 2026, 1:05pm UTC](https://forum.ansible.com/t/host-vars-not-discovered/46042/3 "2026-07-13T13:05:02Z")

</div>

The documentation is kind of ambiguous about how to actually use that layout. I’m guessing it doesn’t work because you’ve configured the inventory source as `inventories/`. Try `ansible-inventory -i inventories/production --list` or `ansible-inventory -i inventories/production/hosts` - if the layout is the same as the example you should see any `host_vars` loaded from the production subdirectory. The [host\_group\_vars](https://docs.ansible.com/projects/ansible/latest/collections/ansible/builtin/host_group_vars_vars.html) plugin loads `host_vars` relative to inventory sources (for example, whatever you pass to `-i`, not to be confused with nested inventory files when the inventory source is a directory).

In case it’s helpful, I have an example of a custom vars plugin that loads vars relative to inventory files regardless of how the inventory sources are specified [here](https://gist.github.com/s-hertel/1fbfcb07f3e871a31c6eb7ff404406cf).

---

<div class="post-metadata">

**Author:** ![aragilar](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/aragilar/32/8642_2.png) [@aragilar](https://forum.ansible.com/u/aragilar)\
**Post date:** [July 14, 2026, 4:57am UTC](https://forum.ansible.com/t/host-vars-not-discovered/46042/4 "2026-07-14T04:57:09Z")

</div>

> [@bvitnik](#):
>
> By providing us with the reproducible example of what does not work 🙂.

Sadly I’m finding it to not be reproducible consistently hence why I asked, I was wondering if it was some old documentation that needed cleaning up.

> [@shertel](#):
>
> The documentation is kind of ambiguous about how to actually use that layout. I’m guessing it doesn’t work because you’ve configured the inventory source as `inventories/`. Try `ansible-inventory -i inventories/production --list` or `ansible-inventory -i inventories/production/hosts` - if the layout is the same as the example you should see any `host_vars` loaded from the production subdirectory. The [host\_group\_vars](https://docs.ansible.com/projects/ansible/latest/collections/ansible/builtin/host_group_vars_vars.html) plugin loads `host_vars` relative to inventory sources (for example, whatever you pass to `-i`, not to be confused with nested inventory files when the inventory source is a directory).

What’s interesting on one machine doing `ansible-playbook -i inventories/ site.yaml` works (usually), but on a different machine it doesn’t. I’m happy to move to a different structure, though it is nice to be able to split up the inventory a bit more.

---

<div class="post-metadata">

**Author:** ![bvitnik](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bvitnik/32/4132_2.png) [@bvitnik](https://forum.ansible.com/u/bvitnik)\
**Post date:** [July 14, 2026, 10:20am UTC](https://forum.ansible.com/t/host-vars-not-discovered/46042/5 "2026-07-14T10:20:42Z")

</div>

Keep in mind that the position of your playbook file in relation to `group_vars` and `host_vars` is also significant. If `group_vars` and `host_vars` are found next to the playbook file (in the same directory), they will be loaded as playbook level vars and have a higher precedence than vars defined at the inventory level (next to an inventory file or inside an inventory directory).

Additionally, there are (or were) some differences in how inventory directory structure is handled across different Ansible versions but that was mostly unintentional. What is guarantied is that in the inventory example from the documentation, passing `-i inventories/production` (inventory dir) or `-i inventories/production/hosts` (inventory file) will work and vars will be properly loaded. Passing the `-i inventories/` will **not** load the vars as `inventories/` is not a proper inventory directory. It’s just a directory holding multiple proper inventory directories. This is what @shertel pointed out.

---

<div class="post-metadata">

**Author:** ![aragilar](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/aragilar/32/8642_2.png) [@aragilar](https://forum.ansible.com/u/aragilar)\
**Post date:** [July 15, 2026, 1:32am UTC](https://forum.ansible.com/t/host-vars-not-discovered/46042/6 "2026-07-15T01:32:27Z")

</div>

Ah, it sounds like the machine this (usually) works on is on a version which has a “feature”/“bug” (depending on your perspective). I think rereading [How to build your inventory — Ansible Community Documentation](https://docs.ansible.com/projects/ansible/latest/inventory_guide/intro_inventory.html#organizing-inventory-in-a-directory) carefully I want to move to grouping via separate files on the same level rather than grouping into directories. I’ll do some tests and see if that works, then I’ll try to make the PR to make the docs clearer.

Thanks both!
