Let's say I have a nginx config file created from a template, which I use to configure certain hosts to redirect a server name from http to https:
server {
listen 80;
server_name {{ server_name }};
rewrite ^ https://$server_name$request_uri? permanent;
}
Say I have two web sites hosted on the same machine:
- site A
- site B
each has its own server name and each needs the redirection above. At the same time let's say I have at least two separate deployment configurations, each represented by its own inventory file and its group_vars/ folder, for example:
- vagrant onebox
- production
each using a different server name. So now I have 2*2 = 4 separate server names:
- sitea.myonebox.com
- siteb.myonebox.com
- sitea.production.com
- siteb.production.com
I can't figure out how to define all of those 4 variables. I can't define two separate variables under group_vars/ because the j2 template expects only one variable name {{server_name}}, so I'd have to define the same template twice to make that work.
The other option is to have sitea and siteb as two separate roles (which I was going to do anyway), and store sever_name in roles/sitea/vars/main.yml, however that setup does not take inventory in consideration, meaning that I'd be down to 2 variables rather than 4.
Is this possible at all without template duplication or is Ansible not supporting this kind of scenario just yet?