# jinja template not evaluating conditional as expected

**URL:** <https://forum.ansible.com/t/jinja-template-not-evaluating-conditional-as-expected/32592>\
**Category:** Ansible Project\
**Created:** [April 3, 2020, 2:58am UTC](https://forum.ansible.com/t/jinja-template-not-evaluating-conditional-as-expected/32592 "2020-04-03T02:58:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_York](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dave\_York](https://forum.ansible.com/u/Dave_York)\
**Post date:** [April 3, 2020, 2:58am UTC](https://forum.ansible.com/t/jinja-template-not-evaluating-conditional-as-expected/32592/1 "2020-04-03T02:58:19Z")

</div>

I have a playbook that calls win\_template:

- name: Template domain.xml  
win\_template:  
src: ‘domain.xml.jinja’  
dest: ‘e:\domain.xml’

Within the template I have this section below. I have confirmed (with a debug statement in the play above) that enable\_target is set to ‘true’.

{% if enable\_agent == ‘true’ %}

{% endif %}

However, after running the play, the jvm-options lines dont appear in the XML file as I would expect. Anyone have any ideas?

Thanks community!

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 3, 2020, 5:35am UTC](https://forum.ansible.com/t/jinja-template-not-evaluating-conditional-as-expected/32592/2 "2020-04-03T05:35:22Z")

</div>

> I have a playbook that calls win\_template:  
> - name: Template domain.xml  
> win\_template:  
> src: 'domain.xml.jinja'  
> dest: 'e:\domain.xml'
> 
> Within the template I have this section below. I have confirmed (with a debug statement in the play above) that  
> enable\_target is set to 'true'.
> 
> {% if enable\_agent == 'true' %}
> 
> ```
> &lt;jvm\-options&gt;
> &lt;option value=&quot;\-javaagent:E:\\Agent\.jar&quot;/&gt;
> &lt;/jvm\-options&gt;
> 
> ```
> 
> {% endif %}
> 
> However, after running the play, the jvm-options lines dont appear in the XML file as I would expect. Anyone have any  
> ideas?
> 
> Thanks community!

It makes more sense to use a boolean instead of the string 'true' for your comparison:

enable\_agent: true

{% if enable\_agent %}  
....  
{% endif %}

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Dave\_York](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dave\_York](https://forum.ansible.com/u/Dave_York)\
**Post date:** [April 3, 2020, 6:18pm UTC](https://forum.ansible.com/t/jinja-template-not-evaluating-conditional-as-expected/32592/3 "2020-04-03T18:18:53Z")

</div>

That worked! Thanks Stefan!

I swear the other way worked for me once, but I like your solution is more graceful.
