How to write a multiline Jinja statement

According to the documentation: https://jinja.palletsprojects.com/en/2.10.x/templates/#line-statements you may use multi-line statements as long as the code has parens/brackets around it. Example: {% if ( (foo == ‘foo’ or bar == ‘bar’) and (fooo == ‘fooo’ or baar == ‘baar’) ) %} <li>some text</li> {% endif %} Edit: Using line_statement_prefix = ‘#’* the code would look like … Read more

How can I test jinja2 templates in ansible?

At this time exists 4 different variants: 1_Online (using https://cryptic-cliffs-32040.herokuapp.com/)Based on jinja2-live-parser code. 2_Interactive (using python and library jinja2, PyYaml) import yaml from jinja2 import Template >>> template = Template(“”” … {% if users is defined and users %} … {% for user in users %}{{ user }} … {% endfor %} … {% endif … Read more

jinja2 how to remove trailing newline

Change your loop to strip whitespace from the top AND bottom of the output (notice extra – at the for loop close): {% for key, value in querystring.items() -%} {{ key }}: ‘{{ value }}’ {%- endfor %} In my tests (using https://github.com/abourguignon/jinja2-live-parser), the – must come after the first {%, not before the last … Read more

Jinja2 template not rendering if-elif-else statement properly

You are testing if the values of the variables error and Already are present in RepoOutput[RepoName.index(repo)]. If these variables don’t exist then an undefined object is used. Both of your if and elif tests therefore are false; there is no undefined object in the value of RepoOutput[RepoName.index(repo)]. I think you wanted to test if certain … Read more

how to iterate over a list of list in jinja

You still need to output the loop variables inside braces. {% for result in results %} <tr> <td>{{ result[0] }}</td> <td>{{ result[1] }}</td> <td>{{ result[2] }}</td> </tr> {% endfor %} Also, consider a nested for loop: {% for result in results %} <tr> {% for elem in result %} <td>{{elem}}</td> {% endfor %} </tr> {% … Read more