# variable\_start\_string not working

**URL:** <https://forum.ansible.com/t/variable-start-string-not-working/24002>\
**Category:** Ansible Project\
**Created:** [March 17, 2017, 6:13pm UTC](https://forum.ansible.com/t/variable-start-string-not-working/24002 "2017-03-17T18:13:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [March 17, 2017, 6:13pm UTC](https://forum.ansible.com/t/variable-start-string-not-working/24002/1 "2017-03-17T18:13:19Z")

</div>

In the docs, there is reference to variable\_start\_string:

[http://docs.ansible.com/ansible/template\_module.html](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  
`

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [March 17, 2017, 6:26pm UTC](https://forum.ansible.com/t/variable-start-string-not-working/24002/2 "2017-03-17T18:26:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 17, 2017, 6:29pm UTC](https://forum.ansible.com/t/variable-start-string-not-working/24002/3 "2017-03-17T18:29:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [March 17, 2017, 6:33pm UTC](https://forum.ansible.com/t/variable-start-string-not-working/24002/4 "2017-03-17T18:33:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [March 17, 2017, 8:14pm UTC](https://forum.ansible.com/t/variable-start-string-not-working/24002/5 "2017-03-17T20:14:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 17, 2017, 8:16pm UTC](https://forum.ansible.com/t/variable-start-string-not-working/24002/6 "2017-03-17T20:16:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 17, 2017, 8:31pm UTC](https://forum.ansible.com/t/variable-start-string-not-working/24002/7 "2017-03-17T20:31:14Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [March 17, 2017, 8:49pm UTC](https://forum.ansible.com/t/variable-start-string-not-working/24002/8 "2017-03-17T20:49:48Z")

</div>

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
