Ansible Jinja2 string comparison
<p>I am getting value of variable "env" in Jinja2 template file using a variable defined in group_vars like:</p>

<pre><code>env: "{{ defined_variable.split('-')[0] }}"
</code></pre>

<p><code>env</code> possible three values could be <code>abc</code>, <code>def</code>, <code>xyz</code>.</p>

<p>On the basis of this value I want to use server URL, whose possible values I have defined inside <code>defaults/main.yml</code> as: </p>

<pre><code>server_abc: https://xxxx.xxx.com
server_def: https://xxxxx.xxx.com
server_xyz: https://xxxx.xxx.com
</code></pre>

<p>In Jinja2 template, I am trying to do:</p>

<pre><code>{% if 'abc'  == "{{env}}" %}
serverURL: '{{ server_abc }}'
{% elif 'def'  == "{{env}}" %}
serverURL: '{{ server_def}}'
{% elif 'xyz' == "{{env}}" %}
 serverURL: '{{ server_xyz }}'
{% else %}
ServerURL: 'server Url not found'
{% endif %}
</code></pre>

<p>However it is always ending up defining <code>ServerURL = "server URL not found"</code> even if <code>env</code> comes with value of <code>abc</code>, <code>def</code> or <code>xyz</code>.</p>

<p>If I try to replace env in Jinja2 template (hardcoded) like below condition does satisfy to true:</p>

<pre><code>     {% if 'abc'  == "abc" %}
     serverURL: '{{ server_abc }}' 
</code></pre>

<p>So that implies me syntax is true but the value of <code>"{{env}}"</code> at run time is not evaluated.</p>

<p>Any suggestion what can I do to solve this?</p>