I am having trouble wrapping my head around how i should setup my variable structure. I have two locations with multiple environments at each. I can have different variables depending on the location and production env.
For example, I have a dev web server at location A and a prod web server at location B. I want them to each have a separate virtual host. What is the best way to accomplish this?
I tried putting variables in the group_vars directory with a separate directory for each location, then subdirectories for each environment, but then I each location is going to pull in every variable from all environments.
I tried just using group_vars (all, webserver, etc) but I couldn't get this to work either unless I have a group_var file for every group at every location for each environment.
The only other thing that I can think of to do to accomplish this is to put the defaults for all groups in group_vars. In my inventory file for each location or environment I can assign a group_var (i.e. env_type=dev). Then in my playbook I can do:
var_files:
- /var/{{ location }}/{{ env_type }}/group_name.ymlI want to avoid duplicating variables that are the same for each env and make the roles as dynamic as possible. I've read through the docs and can't seem to make sense of it. I am sure that Ansible or someone else has figured out. I just cant find it. If someone can point me in the right direction I would really appreciate it.
Thanks.
ansible-playbook -i dev env/dev/playbooks/web-server.yml