jinja2-cli icon indicating copy to clipboard operation
jinja2-cli copied to clipboard

Parse ansible '#jinja2:' overrides

Open mkhon opened this issue 1 year ago • 2 comments

This change allows to use ansible templates as is

mkhon avatar May 11 '23 15:05 mkhon

Is there documentation around what this format is? I've never seen this before.

mattrobenolt avatar May 11 '23 19:05 mattrobenolt

Is there documentation around what this format is? I've never seen this before.

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html

Also, you can override jinja2 settings by adding a special header to template file. i.e. #jinja2:variable_start_string:'[%', variable_end_string:'%]', trim_blocks: False which changes the variable interpolation markers to [% var %] instead of {{ var }}. This is the best way to prevent evaluation of things that look like, but should not be Jinja2.

Basically, any jinja2 environment variables can be set this way

mkhon avatar May 12 '23 12:05 mkhon