I am experimenting with variable overriding in Ansible. To do so, I have created the below-depicted directory structure. Note that under inventories, I have created two separate sites (1 & 2) Also, note that I have added group_vars/host_vars at two different levels; below inventories and each site.
.
├── ansible.cfg
├── inventories
│ ├── group_vars
│ │ └── all.yml
│ ├── host_vars
│ │ └── target2.yml
│ ├── site1
│ │ ├── group_vars
│ │ │ └── all.yml
│ │ ├── host_vars
│ │ │ └── target1.yml
│ │ └── hosts.yml
│ └── site2
│ ├── group_vars
│ │ └── all.yml
│ ├── host_vars
│ │ └── target2.yml
│ └── hosts.yml
├── modules
├── playbooks
│ └── playbook1
│ ├── group_vars
│ │ └── all.yml
│ └── host_vars
└── roles
I would like to be able to store default variables for groups/hosts at "inventories" level and override them when/if necessary at site/group/host level using directories (not the hosts.yml), but I am unable to do so.
If I test the inventory by targeting the base "inventories" directory, I can see that group_vars/host_var folders under sites are ignored:
ansible-inventory --vars --graph -i inventories/
@all:
|--@site1:
| |--target1
| | |--{scope = inventories/site1/hosts.yml}
| |--target2
| | |--{scope = inventories/host_vars/target2.yml}
|--@site2:
| |--target2
| | |--{scope = inventories/host_vars/target2.yml}
|--@ungrouped:
|--{scope = inventories/group_vars/all.yml}
But if I target a specific site, the underlying group_vars/host_var folder are used, but of course the one at base "inventory" are ignored:
ansible-inventory --vars --graph -i inventories/site1
@all:
|--@site1:
| |--target1
| | |--{scope = inventories/site1/host_vars/target1.yml}
| |--target2
| | |--{scope = inventories/site1/group_vars/all.yml}
|--@ungrouped:
|--{scope = inventories/site1/group_vars/all.yml}
ansible-inventory --vars --graph -i inventories/site2
@all:
|--@site2:
| |--target2
| | |--{scope = inventories/site2/host_vars/target2.yml}
| |--{scope = inventories/site2/group_vars/all.yml}
|--@ungrouped:
Is it possible to instruct ansible to look for group_vars/host_var folders in the entire directory structure?
Thanks!