Search code examples
ansiblejinja2defaultliterals

How do I pass a literal value into Jinja2 that is '{{ value }}'


I need to setup a jinja2 template that does this...

"message":"{{ policy.message | default('{{message}}') }}"

If you don't provide anything to override the message, the json template should take a value of {{message}}.

I've tried a couple of things, but I can't seem to get it to work. It keeps returning this error...

'message' is undefined

Any ideas?


Solution

  • I think I figured it out.

    "message":"{{ policy.message | default('{{message}}') }}"
    

    This line does work. It does add it as needed. The problem I was encountering was a post-verification check to print this render out acted as if there was an undefined var. Essentially it renders the template again. Looks like I just need to make that a literal print instead of render and that fixes my problem. Thanks all.