Salt: Jinja file templates with if/elseif/endif statements insert a newline in place of the statement

Created on 24 Mar 2013  路  5Comments  路  Source: saltstack/salt

Jinja template:

{% if grains['os'] == 'Fedora' %}
mailq_path = /usr/bin/mailq.postfix
{% elif grains['os'] == 'Arch' %}
mailq_path = /usr/bin/mailq
{% endif %}

Salt output:

 mailq_path = /usr/bin/mailq.postfix
+

Most helpful comment

Thanks for the info. this came up high in google looking for ideas for salt templating.
Please note that @czee actually has it incorrect. To save others, this is how it should look:

{% if grains['os'] == 'Fedora' -%}
mailq_path = /usr/bin/mailq.postfix
{% elif grains['os'] == 'Arch' -%}
mailq_path = /usr/bin/mailq
{%- endif %}

Notice the dash to the right of the percentage sign in the endif line.

All 5 comments

Thanks, my mistake! Closing this. For anyone else reading this, the fix is this:

{% if grains['os'] == 'Fedora' -%}
mailq_path = /usr/bin/mailq.postfix
{% elif grains['os'] == 'Arch' -%}
mailq_path = /usr/bin/mailq
{-% endif %}

Thanks for the info. this came up high in google looking for ideas for salt templating.
Please note that @czee actually has it incorrect. To save others, this is how it should look:

{% if grains['os'] == 'Fedora' -%}
mailq_path = /usr/bin/mailq.postfix
{% elif grains['os'] == 'Arch' -%}
mailq_path = /usr/bin/mailq
{%- endif %}

Notice the dash to the right of the percentage sign in the endif line.

How to include same Jinja2 template with ansible. Can anyone help me?

hey @kumaran85 ,

You need to use Ansible's template module. And I believe the question should be asked on Ansible forums or GitHub page.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Oloremo picture Oloremo  路  3Comments

mooperd picture mooperd  路  3Comments

Arguros picture Arguros  路  3Comments

Inveracity picture Inveracity  路  3Comments

qiushics picture qiushics  路  3Comments