Ultimate way to escape braces? (strange corner case inside)

With Ansible 1.9.2 and this playbook:

---
- name: test
� hosts: localhost
� connection: local
� tasks:
��� - name: register variable
����� shell: >
������� echo {% raw %} '{{ .Suddenly.Go.Template.String }}' {% endraw %}
����� register: var
��� - debug:
������� var: var

After invoking like it: ansible-playbook test.yml
You will get this:

fatal: [localhost] => Failed to template {{var}}: Failed to template echo '{{ .Suddenly.Go.Template.String }}': template error while templating string: unexpected '.'

I actually barely understand, why it may happen. Seems like Ansible renders var twicely, and in a second pass it cannot parse Go template string. Or I’m doing something wrong?

The **.**Suddenly.Go.Template.String is not valid Ansible variable name. Take a look on “What Makes A Valid Variable Name” section of Ansible documentation.

it cannot parse Go template string

I suppose it just typo, but to be clear Ansible support only jinja2 template language.

The Go template part is not expected to be parsed by Ansible’s template engine at all, and it’s enclosed in {% raw %}...{``% endraw %} tag because of that.

Hi Andrew, now it’s more clear. I did not realize what you want to achieve at first. According to the Jinja docs it should work:

shell: >
echo {% raw %} {{ ‘{{.Suddenly.Go.Template.String }}’ }} {% endraw %} > /tmp/test