Hi,
I’ve been using ansible for half a year and have been really happy with it so far, so first of all: thanks for all the great work on this project!
We’re moving from static to dynamic inventory, but I’m having trouble with loading group_vars and haven’t been able to find out from the docs how these are looked up, so I hope someone can help me out here.
In the static setup we had one inventory file per environment (dev/staging/prod), and a group_vars directory where we set variables per role as well as per environment based on their group membership.
The static directory structure looks like this:
`
inventories
├── development
├── group_vars
│ ├── all.yml
│ ├── web.yml
│ ├── worker.yml
│ ├── development
│ ├── secrets.yml
│ └── vars.yml
│ ├── production
│ ├── secrets.yml
│ └── vars.yml
│ └── staging
│ ├── secrets.yml
│ └── vars.yml
├── production
└── staging
`
When I run e.g.:
ansible -i inventories/staging web -m debug -a 'msg="{{hostvars}}"'
the results contain all the relevant vars for the groups ‘all’, ‘web’ and ‘staging’.
Things I like about this setup:
- you have to explicitly pick an environment to target, which makes accidents more difficult;
- production and staging inventories are completely separate, again making mistakes harder;
- having a single place where we can set some variables for all hosts and override them and add more, by role (web, worker, etc) and by environment.
The new mixed inventory setup looks like this (staging and production are now directories, maybe that’s part of the issue?):
`
inventories
├── development
├── group_vars
│ ├── all.yml
│ ├── web.yml
│ ├── worker.yml
│ ├── development
│ │ ├── secrets.yml
│ │ └── vars.yml
│ ├── grabber.yml
│ ├── production
│ │ ├── secrets.yml
│ │ └── vars.yml
│ └── staging
│ ├── secrets.yml
│ └── vars.yml
├── production
│ ├── base
│ ├── ec2.ini
│ └── ec2.py
└── staging
├── base
├── ec2.ini
└── ec2.py
`
The output of
ansible -i inventories/staging/ web -m debug -a 'msg="{{hostvars}}"'
now doesn’t include any of the group vars. The group_vars directory doesn’t seem to be loaded or applied at all.
Any ideas how I can structure this to achieve what we had previously but with mixed inventory?
Thanks!
Niko
PS: In case you’re wondering, the two ec2.py scripts are identical and the ec2.ini’s only differ in their cache_path and instance_filters (selecting instances tagged with env:production/staging, respectively).
Our mailing address is: WhiteMatter Labs GmbH | Reichenberger Str. 124, 10999 Berlin
Handelsregister: Amtsgericht Charlottenburg, HRB 162605 B | Geschäftsführer: Fabian Stelzer