# Escaping { character in a task that has an ansible variable

**URL:** <https://forum.ansible.com/t/escaping-character-in-a-task-that-has-an-ansible-variable/26955>\
**Category:** Ansible Project\
**Created:** [March 10, 2018, 3:46pm UTC](https://forum.ansible.com/t/escaping-character-in-a-task-that-has-an-ansible-variable/26955 "2018-03-10T15:46:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![William\_Muriithi](https://avatars.discourse-cdn.com/v4/letter/w/6de8d8/32.png) [@William\_Muriithi](https://forum.ansible.com/u/William_Muriithi)\
**Post date:** [March 10, 2018, 3:46pm UTC](https://forum.ansible.com/t/escaping-character-in-a-task-that-has-an-ansible-variable/26955/1 "2018-03-10T15:46:14Z")

</div>

Hello all,

I have a task that need to run the command below:

ipa dnsrecord-add idm.example.com cluster --a-rec={192.0.2.40,192.0.2.41}

The problem is that the IPA and ansible both use the "{" character. I  
have attempted to escape one of the "{" with a back slash, and ansible  
is fine with that, but then the resulting command isn't valid as far  
as IPA server is concerned.

How would you guys go about resolving this? This is what I am seeing.

# please read this.  
[https://access.redhat.com/documentation/en-us/red\_hat\_enterprise\_linux/7/html/linux\_domain\_identity\_authentication\_and\_policy\_guide/retrieve-existing-keytabs](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/linux_domain_identity_authentication_and_policy_guide/retrieve-existing-keytabs)

&nbsp;&nbsp;&nbsp;&nbsp;- name: Create a DNS FQDN that will be shared by both active and  
replica systems

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: ipa dnsrecord-add eng.example.com {{service\_username}}  
--a-rec=[{{ cluster\_IP|join(",") }}]

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: "{{ipa\_server}}"

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tags:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- svn\_load\_balancing\_1

TASK [svn : Create a DNS FQDN that will be shared by both active and  
replica systems]

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 10, 2018, 7:04pm UTC](https://forum.ansible.com/t/escaping-character-in-a-task-that-has-an-ansible-variable/26955/2 "2018-03-10T19:04:34Z")

</div>

I don't now why you have those square brackets in there since you command should not have them according to your command on top.  
To get the curly bracket in just use string concatenation.

--a-rec={{ '{' ~ ip | join(',') ~ '}' }}

---

<div class="post-metadata">

**Author:** ![Sakshi\_Rathore](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Sakshi\_Rathore](https://forum.ansible.com/u/Sakshi_Rathore)\
**Post date:** [February 22, 2021, 1:15pm UTC](https://forum.ansible.com/t/escaping-character-in-a-task-that-has-an-ansible-variable/26955/3 "2021-02-22T13:15:41Z")

</div>

Hello Kai Stian Olstad

further to this context, could you please advise how to escape square bracket from the output in ansible?
