If you are following the best practices documented (https://docs.ansible.com/intro_configuration.html#roles-path), it should be pulling in those group_vars variables, if the host(s) being applied to the plays/playbooks are within the defined groups that contain the variables.
Where is the group_vars folder relative to the playbooks that are not “seeing” the variables?
To further confirm, please post an example in pastebin.
├── playbook1.yml <---- these pick up the group_vars
├── playbook2.yml
├── playbook3.yml
├── playbook_sub_dir
│ ├── playbook4.yml <---- these don’t pick up the group_vars
│ ├── playbook5.yml
│ └── playbook6.yml
I’ll try and knock together an example. I can’t include the actual project as there is a fair amount of sensitive information…
The issue is just with the playbooks in the sub directories. I can get them to hit the roles by referencing them with …/ its just the group_vars that aren’t getting picked up
Im just looking to organise the playbooks as im starting to get a lot in the root directory
Group vars can sit next to your inventory or next to your playbook. Looks like your current groupvars are evaluated because they sit next to yout root-dir playbooks.
You can try to put them next to your inventory so that they’ll be evaluated for every pkaybook that’s run with that inventory.
There are many inventories. Currently I have all plays use the groups defined in the main group_vars. If I was to move some common groups_vars to the inventory then they would be duplicated for each inventory. Unless im missing something
I was hoping there would be a way of having ansible look at the playbook_dir instead of its current dir when evaluating the group_vars.
There was another thread about that yesterday. No good option that i know of. You can try to create a link to your var files inside each invetory, or write another inventory script that includes these files.
Interesting read though that seems to concern itself with the group_var / inventory layouts. I don't really have a problem there. Just the playbook sub directories not picking up the variables. If I ignore the idea of tidying playbooks by sub directory everything works well. Symlinks seem a bit dirty and error prone, though as mentioned they would be preserved by git which could work as long as they are relative.