Hi,
i want to create a template which should result in the following output:
- 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.