AWX - How to use group_vars and host_vars when playbooks are in a subdirectory?

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:

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?

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:

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 …”

1 Like

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.

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

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.

Ansible also loads host and group variable files by searching paths relative to the inventory file or the playbook file. 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.

No.