Maybe try these expressions:
{{ '{' ~ lookup('ansible.builtin.env', 'QUALYS_ACTIVATIONID') ~ '}' }}
{{ '{' ~ lookup('ansible.builtin.env', 'QUALYS_CUSTOMERID') ~ '}' }}
On 11/4/23 10:35 PM, matthew Higgs wrote:
Hey. I am having a bit of trouble trying to convert a jinja template
because of the some issues escaping curly braces. Consider this simple
jinja template that is currently returning an error:
activationID: {{{ lookup('ansible.builtin.env', 'QUALYS_ACTIVATIONID') }}}
CustomerID: {{{ lookup('ansible.builtin.env', 'QUALYS_CUSTOMERID') }}}
As you can see, there is an environment variable storing a string
value that I need, but the final string that my playbook needs is that
value surrounded by single curly brackets, eg:
{34-34-456-34}
I have tried various methods I found online to attempt to get ansible
to properly convert the jinja template, including:
Example 1:
activationID: \{{{ lookup('ansible.builtin.env',
'QUALYS_ACTIVATIONID') }}\}
CustomerID: \{{{ lookup('ansible.builtin.env', 'QUALYS_CUSTOMERID') }}\}
Example 2:
activationID: "{{{ lookup('ansible.builtin.env',
'QUALYS_ACTIVATIONID') }}}"
CustomerID: "{{{ lookup('ansible.builtin.env', 'QUALYS_CUSTOMERID') }}}"
Example 3:
activationID: "\{{{ lookup('ansible.builtin.env',
'QUALYS_ACTIVATIONID') }}\}"
CustomerID: "\{{{ lookup('ansible.builtin.env', 'QUALYS_CUSTOMERID') }}\}"
But no matter what I try, I keep getting this error:
The error was: . expected token ':', got '}
I did notice some interesting output from ansible regarding how the
template is being parsed as I ran the examples listed above. For
example, the output when I ran example 1:
String: activationID: \\{{{ lookup('ansible.builtin.env',
'QUALYS_ACTIVATIONID') }}\\}\nCustomerID: \\{{{
lookup('ansible.builtin.env', 'QUALYS_CUSTOMERID') }}\\}\n. expected
token ':', got '}'"
As you can see, "\" which I want to escape the outer most curly brace
is itself being automatically escaped by ansible. Same when I run
example 3:
"msg": "AnsibleError: template error while templating string: expected
token ':', got '}'. String: activationID: \"\\{{{
lookup('ansible.builtin.env', 'QUALYS_ACTIVATIONID')
}}\\}\"\nCustomerID: \"\\{{{ lookup('ansible.builtin.env',
'QUALYS_CUSTOMERID') }}\\}\"\n. expected token ':', got '}'"
I am at a loss as to what to do here. Any help would be awesome.
--
You received this message because you are subscribed to the Google
Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/4c276d28-e411-4ac5-b6b3-df42165d50b8n%40googlegroups.com
<https://groups.google.com/d/msgid/ansible-project/4c276d28-e411-4ac5-b6b3-df42165d50b8n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Todd
--
You received this message because you are subscribed to the Google Groups "Ansible
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/f5a486a9-c30f-4d82-ae14-647dab2d4e99%40gmail.com.