variable_start_string not working

In the docs, there is reference to variable_start_string:

http://docs.ansible.com/ansible/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 }}.

However, I cannot seem to get this to work.

I always get this error:

template error while templating string: unexpected ‘.’.

Here is my specific use case:

roles/profile.d/tasks/main.yml
`

Note that I’m testing the above on 2.2.1.

I also tried running from git on tag: v2.3.0.0-0.1.rc1

with the exact same results.

that you set those settings for that specific template, will not
affect Ansible's templating itself, so the with_ will use normal
templating BEFORE passing all the info to the template module which
will then make those settings effective on the template supplied, but
not to any other part of the task.

I figured as much. And setting that doesn’t apply to the task itself, apparently.

I’m pondering how difficult it would be to create a filter that allows passing all contents of a variable withOUT interpolating any {{ }} pairs.

very, as arguments to filters get templated before being passed in

A workaround is pretty easy
Replace { with # and } with ¤

And use the replace filter in the template
{{ item.contents | replace("#", "{") | replace("¤", "}")

That’s a fantastic workaround.

I got a unicode error, so ended up with the following:

{{ item[‘contents’] | replace(“~~”, “{{”) | replace(“``”, “}}”) }}

And all is working now. Thanks!

–Shaun