Is it possible to ignore variable substitution in templates? I've attempted {% raw %}, {% verbatim %}, slash escaping, and using jinja to output braces.
Reason: I am writing a playbook that generates playbooks; so need to preserve the curly braces. Here's an example:
<mytemplate.j2>
===
Test: Preserve curly braces, and NOT perform variable substitution:
First Attempt:
{% raw %}
- { include: "{{ myvar }}" }
{% endraw %}
Second Attempt:
- { include: "{{ '{{' }} myvar {{ '}}' }}" }
<playbook.yml>
===
---
- name: "test raw template output"
hosts: localhost
vars:
myvar: "foo"
tasks:
- local_action: template src="mytemplate.j2" dest="/tmp/myoutput.txt"
</tmp/myoutput.txt>
===
Test: Preserve curly braces, and NOT perform variable substitution:
First Attempt:
- { include: "foo" }
Second Attempt:
- { include: "foo" }
The desired output, of course, is:
First Attempt
- { include: "{{ myvar }}" }
Can someone direct me on how to escape variable substitution? In my production scenario, I actually need variable substition to happen in parts of the template, and to NOT happen in other parts; hence not being able to use copy.