I need to escape double curly braces in a code I'm working on using Ansible. The thing is I have all those parameters that needs to be transformed in variables. Basically I'm working on a template creator.
I've tried using {% raw %}{{ name-of-variable }}{% endraw %}
but it did not work. When I tried /{/{ name-of-variable \}\}
I almost got it, but I am trying to get rid of the backslashes too.
Here's a bit of the code:
local_action:
module: replace
path: "/tmp/{{ ambiance }}/{{ seed }}DEFAULT.j2"
regexp: "{{ item.regexp1 }}"
replace: "{{ item.replace }}"
with_items:
- { regexp1: '^DBHOST.*$', replace: 'DBHOST = {% raw %}{{ databasehost }}{% endraw %}' }
- { regexp1: '^GLOBALHOST.*$', replace: 'GLOBALHOST = {% raw %}{{ global_hostname }}{% endraw %}' }
I expect the following result:
DBHOST = {{ satabasehost }}
GLOBALHOST = {{ global_hostname }}
Any suggestions/ideas?