Dashes in jinja templates

Turns out that + and – are there for whitespace control purpose. You can manually disable the lstrip_blocks behavior by putting a plus sign (+) at the start of a block […] You can also strip whitespace in templates by hand. If you put an minus sign (-) to the start or end of an … Read more

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

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

Ansible: filter a list by its attributes

To filter a list of dicts you can use the selectattr filter together with the equalto test: network.addresses.private_man | selectattr(“type”, “equalto”, “fixed”) The above requires Jinja2 v2.8 or later (regardless of Ansible version). Ansible also has the tests match and search, which take regular expressions: match will require a complete match in the string, while … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)