# AWX - How to use group\_vars and host\_vars when playbooks are in a subdirectory?

**URL:** <https://forum.ansible.com/t/awx-how-to-use-group-vars-and-host-vars-when-playbooks-are-in-a-subdirectory/10327>\
**Category:** Get Help\
**Tags:** playbook, awx\
**Created:** [October 16, 2024, 11:11am UTC](https://forum.ansible.com/t/awx-how-to-use-group-vars-and-host-vars-when-playbooks-are-in-a-subdirectory/10327 "2024-10-16T11:11:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![actionjackson](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@actionjackson](https://forum.ansible.com/u/actionjackson)\
**Post date:** [October 16, 2024, 11:11am UTC](https://forum.ansible.com/t/awx-how-to-use-group-vars-and-host-vars-when-playbooks-are-in-a-subdirectory/10327/1 "2024-10-16T11:11:02Z")

</div>

I need help configuring group\_vars and host\_vars in Ansible AWX when playbooks are in a subdirectory and not in the root directory.

Here is my directory structure:

```auto
inventory/
  group_vars/
    all/
       all.yml
  inventory
playbooks/
  test_group_vars.yml
ansible.cfg

```

On CLI everything works as expected, in AWX I get this error:

> “my\_group\_var”: “VARIABLE IS NOT DEFINED!”

It only works in AWX, if I put my group\_vars under the playbooks dir. AWX does not find the variables either in group\_vars or inventory/group\_vars.

I have seen multiple “best practice” project structures with group\_vars inside an inventory subdir. Is it possible to put group\_vars/host\_vars outside of my playbook folder for AWX?

Do I need to set `playbook_dir` or `playbook_vars_root`?

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 16, 2024, 5:39pm UTC](https://forum.ansible.com/t/awx-how-to-use-group-vars-and-host-vars-when-playbooks-are-in-a-subdirectory/10327/2 "2024-10-16T17:39:02Z")

</div>

Welcome to the forum, @actionjackson !

Please accept my sincere apology if this response comes across as somewhat blunt or even harsh, especially as this is in response to your first post. We’ve got a very supportive community growing here, and we all wish you and each other great success in our Ansible journey. That said, if you were hiking and saw someone you just met about to step into a pit or off a ledge, how would you balance shouting vs. politeness? That’s my dilemma. So I write:

> [@actionjackson](#):
>
> On CLI everything works as expected

Then some setting is different on the CLI. Run  
`ansible-config dump --only-changed`  
to see how your config differs from standard, and [if you insist on pursuing this ill-advised scheme] see if you can replicate that config in ~~AWS~~ AWX.

There are many threads on various discussion platforms where people try to put playbooks in places other than the top level of their Ansible projects. There’s a theme here along the lines of, “Dr., it hurts when I do this …”

---

<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:** [October 23, 2024, 4:11pm UTC](https://forum.ansible.com/t/awx-how-to-use-group-vars-and-host-vars-when-playbooks-are-in-a-subdirectory/10327/3 "2024-10-23T16:11:06Z")

</div>

Unfortunately, I don’t think it works, and the `playbook_dir` and `playbook_vars_root` config options won’t be able to help. This looks like the same issue: [group\_vars and host\_vars ignored when placed inside inventory folder (as per Ansible documentation) · Issue #15438 · ansible/awx · GitHub](https://github.com/ansible/awx/issues/15438).

Maybe creating a group\_vars symlink (in ./playbooks) to the inventory-relative group\_vars directory would workaround the issue?

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [October 24, 2024, 6:34am UTC](https://forum.ansible.com/t/awx-how-to-use-group-vars-and-host-vars-when-playbooks-are-in-a-subdirectory/10327/4 "2024-10-24T06:34:02Z")

</div>

> [@actionjackson](#):
>
> I have seen multiple “best practice” project structures with group\_vars inside an inventory subdir. Is it possible to put group\_vars/host\_vars outside of my playbook folder for AWX?

Yes, you can put your inventory wherever you like, as long as you follow the inventory structure and let Ansible know where to look for it. In CLI you do that with ansible.cfg or the `-i` option. In AWX you specify the inventory when creating the job template.

> [@actionjackson](#):
>
> It only works in AWX, if I put my group\_vars under the playbooks dir.

Ansible also [loads host and group variable files by searching paths relative to the inventory file or the playbook file](https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#organizing-host-and-group-variables). So if you place `host_vars` and `group_vars` in the root of you playbook directory, Ansible will find those variables and append or overwrite those from your inventory.

> [@actionjackson](#):
>
> Do I need to set `playbook_dir` or `playbook_vars_root`?

No.
