Need help with escaping a jinja-sequence in bash script

Hi,

i want to create a template which should result in the following output:

  1. custommark4 masq 1 PREROUTING inface “${openvpn_if}”

Here, the value “openvpn” should be read from a variable. I have some problems with creating proper jinja2-Syntax because of the curly brackets which are already there.
My first solution was just plain

"${{{ item.name }}_if}"

which resulted in a parsing error: AnsibleError: ERROR! template error while templating string: expected token ‘:’, got ‘}’"

So i consulted the jinja documentation which specified that i could just escape characters with ’
The second attempt was:
"$'{'{{ item.name }}_if}"

This was accepted by jinja, but resulted in “$'{'openvpn_if}” (notice the ’ around the first curly bracket). This is no valid bash syntax.

So, how could i escape these brackets correctly?

…and for those wondering why i create bash scripts with ansible: I am managing a server side firewall with the great FireHOL-utility which is an abstraction layer for the iptables-command. And it’s config files are using plain bash syntax.

I found this:
http://jinja.pocoo.org/docs/dev/templates/#escaping

Which says:
<quote>
The easiest way to output a literal variable delimiter ({{) is by
using a variable expression:

{{ '{{' }}
</quote>

So I would try this (untested):

"${{'{'}}{{ item.name }}_if}"

Johannes

“${{‘{’}}{{ item.name }}_if}”

Ah, stupid me. I should have read the documentation correctly. Will definitely try this, thanks.

Yes, this works.