Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting error when I am trying to put expression inside a jinja template

I want to put an expression such as

"Host(`{{ .Name }}.access.{{website_tld}}`)"`

inside my jinja2 template static_traefik.yml.j2 so that {{ .Name }} should stay as is but {{website_tld}} should get replaced when I am running ansible task.

However this is throwing a massive error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"AnsibleError: template error while templating string: unexpected char '\\\\' at 1016.
consulCatalog:\n    defaultRule: f\"Host(`{{{{ \\.Name }}}}.access.{{website_tld}}`)\"

>Solution :

Checkout jinja escaping
https://jinja.palletsprojects.com/en/3.0.x/templates/#escaping

So both would work:

"Host(`{% raw %}{{ .Name }}{% endraw %}.access.{{website_tld}}`)"
"Host(`{{ "{{ .Name }}" }}.access.{{website_tld}}`)"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading