# Issue escaping curly braces in template file

**URL:** <https://forum.ansible.com/t/issue-escaping-curly-braces-in-template-file/38569>\
**Category:** Ansible Project\
**Created:** [November 5, 2023, 2:35am UTC](https://forum.ansible.com/t/issue-escaping-curly-braces-in-template-file/38569 "2023-11-05T02:35:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew\_Higgs](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@matthew\_Higgs](https://forum.ansible.com/u/matthew_Higgs)\
**Post date:** [November 5, 2023, 2:35am UTC](https://forum.ansible.com/t/issue-escaping-curly-braces-in-template-file/38569/1 "2023-11-05T02:35:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [November 6, 2023, 3:31pm UTC](https://forum.ansible.com/t/issue-escaping-curly-braces-in-template-file/38569/2 "2023-11-06T15:31:52Z")

</div>

Maybe try these expressions:

```auto
{{ '{' ~ lookup('ansible.builtin.env', 'QUALYS_ACTIVATIONID') ~ '}' }}
{{ '{' ~ lookup('ansible.builtin.env', 'QUALYS_CUSTOMERID') ~ '}' }}

```

```auto

```

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [November 6, 2023, 6:08pm UTC](https://forum.ansible.com/t/issue-escaping-curly-braces-in-template-file/38569/3 "2023-11-06T18:08:36Z")

</div>

If you need this a lot then you could even dedicate a filter to it.  
For example, create a directory called ‘filter\_plugins’ adjacent to your playbook and then create a file called ‘filters.py’ that contains:

def embrace(string):  
return ‘{’ + string + ‘}’  
class FilterModule(object):  
def filters(self):  
return {  
‘embrace’: embrace  
}

Now you can do:

activationID: “{{ lookup(‘ansible.builtin.env’, ‘QUALYS\_ACTIVATIONID’) | embrace }}”  
CustomerID: “{{ lookup(‘ansible.builtin.env’, ‘QUALYS\_CUSTOMERID’) | embrace }}”

Dick
