jinja template not evaluating conditional as expected

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!

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' %}

            <jvm\-options>
                <option value="\-javaagent:E:\\Agent\.jar"/>
            </jvm\-options>

{% 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
         Racke

That worked! Thanks Stefan!

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