0

Based on the following Ansible inventory directory tree:

inventories/region
├── staging
│   ├── group_vars
│   │   ├── all.yml
│   │  
│   │── hosts.yml
│   └── site1
│       ├── group_vars
│       │   ├── all.yml
│       │  
│       ├── hosts.yml
│       
├── group_vars
│   └── all.yml
└── prod
    ├── group_vars
    │   ├── all.yml
    │── hosts.yml
    ├── site1
    │   ├── group_vars
    │   │   ├── all.yml
    │── hosts.yml
    └──site2
        ├── group_vars
        │   ├── all.yml
        │── hosts.yml

Is there a way for me to load vars from inventories/region/group_vars/all.yml and inventories/region/env/group_vars/all.yml inside inventories/region/env/siteX/group_vars/all.yml? I will be calling playbooks with the reference to the site-specific inventory files, such as inventories/region/prod/site2/group_vars/all.yml. I'm trying to avoid maintaining the same variables with the same values across multiple var files (group_vars/all.yml in this example) for each site and environment.

The value of the variables will change for different regions.

Thanks

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
Lubos A.
  • 1
  • 2
  • 1
    Where is "env" in your directory tree? – ceving Dec 02 '19 at 10:25
  • Maybe this helps: https://stackoverflow.com/questions/40606890/how-to-share-group-vars-between-different-inventories-in-ansible – ceving Dec 02 '19 at 10:27
  • Thanks to Zeitounator for fixing the directory tree. I'm trying to find a way to have each child branch inherit vars set in the group_vars of the parent branches (or any other method), so I do not need to maintain duplicate vars in each child branch. So, based on the example tree above, I'd like to set region specific varA, then env specific varB and site specific varC without maintaining identical varA and varB in the group_vars under "site1" and "site2" for "prod" or "staging" environments. I hope this clarifies the question. – Lubos A. Dec 08 '19 at 02:37
  • You can use [include_vars](https://docs.ansible.com/ansible/latest/modules/include_vars_module.html) or symbolic links in the file system, but I would not got that way. – ceving Dec 09 '19 at 07:53

0 Answers0