Escaping double curly braces in Ansible

Whenever you have problems with conflicting characters in Ansible, a rule of thumb is to output them as a string in a Jinja expression. So instead of {{ you would use {{ ‘{{‘ }}: – debug: msg=”docker inspect –format ‘{{ ‘{{‘ }} .NetworkSettings.IPAddress {{ ‘}}’ }}’ instance1″ Topic “Escaping” in the Jinja2 docs.

Jinja2 inline comments

Jinja2 has no support for comments within a {{ … }} statement. You can only use comments outside of such statements, and then only with {# .. #} or ## comment. {# .. #} is only meant for disabling part of a template or adding comments outside of other Jinja2 syntax. You can’t nest these. … Read more

Split string into list in jinja?

After coming back to my own question after 5 year and seeing so many people found this useful, a little update. A string variable can be split into a list by using the split function (it can contain similar values, set is for the assignment) . I haven’t found this function in the official documentation … Read more

How to iterate through a list of dictionaries in Jinja template?

Data: parent_list = [{‘A’: ‘val1’, ‘B’: ‘val2’}, {‘C’: ‘val3’, ‘D’: ‘val4’}] in Jinja2 iteration: {% for dict_item in parent_list %} {% for key, value in dict_item.items() %} <h1>Key: {{key}}</h1> <h2>Value: {{value}}</h2> {% endfor %} {% endfor %} Note: Make sure you have the list of dict items. If you get UnicodeError may be the value … Read more

Link to Flask static files with url_for

You have by default the static endpoint for static files. Also Flask application has the following arguments: static_url_path: can be used to specify a different path for the static files on the web. Defaults to the name of the static_folder folder. static_folder: the folder with static files that should be served at static_url_path. Defaults to … Read more