Controlling whitespace in Jinja2 templates: Difference between revisions
use spaces |
add example of Ansible weirdness with templates |
||
| Line 64: | Line 64: | ||
As the '''very first line''' of your template file, you can use a magic comment directive to control the behavior of the Ansible Template module | As the '''very first line''' of your template file, you can use a magic comment directive to control the behavior of the Ansible Template module | ||
<code>#jinja2: trim_blocks: "true", lstrip_blocks: "true"</code><ref>It's unclear whether the boolean value(s) to be quoted. I believe it was a bug that is now fixed - meaning they can be bare.</ref> | <code>#jinja2: trim_blocks: "true", lstrip_blocks: "true"</code><ref>It's unclear whether the boolean value(s) to be quoted. I believe it was a bug that is now fixed - meaning they can be bare.</ref> | ||
Given this code in the template: | |||
"config": { | |||
{%- if overwrite_local_changes %} | |||
"discard-changes": true | |||
{%- else %} | |||
"discard-changes": false | |||
{%- endif %} | |||
} | |||
We could not get the result from Ansible that we could get from the liver parser (and what we expected); namely that the closing brace would be on a line by itself. | |||
"config":•{ | |||
••••"discard-changes":•true | |||
} | |||
Ansible puts the closing brace on the same line as the output. | |||
"config":•{ | |||
••••••••••••"discard-changes":•true••••} | |||
==By hand== | ==By hand== | ||