Note that there are some explanatory texts on larger screens.

plurals
  1. POAnsible: are variables for specific role and inventory possible?
    text
    copied!<p>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:</p> <pre><code>server { listen 80; server_name {{ server_name }}; rewrite ^ https://$server_name$request_uri? permanent; } </code></pre> <p>Say I have two web sites hosted on the same machine:</p> <ul> <li>site A</li> <li>site B</li> </ul> <p>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:</p> <ul> <li>vagrant onebox</li> <li>production</li> </ul> <p>each using a different server name. So now I have 2*2 = 4 separate server names:</p> <ul> <li>sitea.myonebox.com</li> <li>siteb.myonebox.com</li> <li>sitea.production.com</li> <li>siteb.production.com</li> </ul> <p>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.</p> <p>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.</p> <p>Is this possible at all without template duplication or is Ansible not supporting this kind of scenario just yet?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload