Folks,
I’d like to get some feedback from the experts here about the proper way to lay out inventory group_vars.
When ansible was set up in my organization the developer decided to split inventory into two groups, devqa and prod.
So when we run a playbook we point to one or the other inventory:
ansible-playbook -i …/devqa_inventory/ -limit $hosts playbook/xyz.yml
ansible-playbook -i …/prod_inventory/ -limit $hosts playbook/xyz.yml
Within each inventory are
top level files that associate hosts with groups:
devqa_inventory/aws.yml:
[aws]:
- host1
- host2
- host3
a group_vars directory
devqa_inventory/group_vars/aws.yml:
a host_vars directory
devqa_inventory/host_vars/host1.yml:
devqa_inventory/host_vars/host2.yml:
devqa_inventory/host_vars/host3.yml:
When we make changes to the playbooks we test them against the devqa inventory hosts and once we’re satisfied they work we apply them to the prod hosts. This seems fine.
When we need to make changes to group_vars we develop them in devqa and run them against devqa hosts, and when we’re satisfied they are correct we manually copy the appropriate changes from devqa inventory to prod inventory. This strikes me as problematic and potentially error prone.
I’m not sure I understand exactly why the original developer (who has since departed) laid this out in this fashion, and I wanted to ask this group whether or not it seemed reasonable. If you think it is problematic, how would you have advised group_vars be handled with ansible-playbook? Woulod have have gone with one big inventory that held everything?
How would you handle the distinction between dev and prod for testing/development and release?
A simple example of one group_vars variable that I could see needing to be different between dev and prod would be an AWS region value. For example say that your development region is us-east-1 and your production region is us-west-1. Under the scheme we’re using right now that’d be one variable you needed to make sure didn’t get copied over. But how should it be laid out if you had one big inventory? At the host_vars level? A jinja2 expression that switched on something that defined dev vs. prod (e.g., at the host_vars define ‘type: dev’ or ‘type: prod’?