Escaping { character in a task that has an ansible variable

180 views
Skip to first unread message

William Muriithi

unread,
Mar 10, 2018, 10:46:30 AM3/10/18
to ansible...@googlegroups.com
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

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

shell: ipa dnsrecord-add eng.example.com {{service_username}}
--a-rec=[{{ cluster_IP|join(",") }}]

delegate_to: "{{ipa_server}}"

tags:

- svn_load_balancing_1




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

task path: /etc/ansible/roles/svn/tasks/main.yml:193

fatal: [temp20.eng.example.com]: FAILED! => {

"failed": true,

"msg": "template error while templating string: expected token
':', got '}'. String: ipa dnsrecord-add eng.example.com
{{service_username}} --a-rec={{{ cluster_IP|join(\",\") }}}"

}

to retry, use: --limit @/etc/ansible/site.retry


PLAY RECAP ************************************************************************************************************************************************************************

temp20.eng.example.com : ok=3 changed=0 unreachable=0 failed=1



tion": {"module_args": {"warn": true, "executable": null,
"_uses_shell": true, "_raw_params": "ipa dnsrecord-add eng.example.com
temp30 --a-rec=[192.168.20.226,192.168.20.227]", "removes": null,
"creates": null, "chdir": null}}, "warnings": []}\r\n', 'Shared
connection to lithium.eng.example.com closed.\r\n')

fatal: [temp20.eng.example.com -> lithium.eng.example.com]: FAILED! => {

"changed": true,

"cmd": "ipa dnsrecord-add eng.example.com temp30
--a-rec=[192.168.20.226,192.168.20.227]",

"delta": "0:00:02.067984",

"end": "2018-03-10 10:25:17.970547",

"failed": true,

"invocation": {

"module_args": {

"_raw_params": "ipa dnsrecord-add eng.example.com temp30
--a-rec=[192.168.20.226,192.168.20.227]",

"_uses_shell": true,

"chdir": null,

"creates": null,

"executable": null,

"removes": null,

"warn": true

}

},

"rc": 1,

"start": "2018-03-10 10:25:15.902563",

"stderr": "ipa: ERROR: invalid 'ip_address': invalid IP address format",

"stderr_lines": [

"ipa: ERROR: invalid 'ip_address': invalid IP address format"

],

"stdout": "",

"stdout_lines": []

}

to retry, use: --limit @/etc/ansible/site.retry



Regards,
William

Kai Stian Olstad

unread,
Mar 10, 2018, 2:04:50 PM3/10/18
to ansible...@googlegroups.com
On Saturday, 10 March 2018 16.46.14 CET William Muriithi wrote:
> 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.
>
> - name: Create a DNS FQDN that will be shared by both active and
> replica systems
>
> shell: ipa dnsrecord-add eng.example.com {{service_username}}
> --a-rec=[{{ cluster_IP|join(",") }}]

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(',') ~ '}' }}


--
Kai Stian Olstad

Sakshi Rathore

unread,
Feb 22, 2021, 8:15:41 AM2/22/21
to Ansible Project
Hello  Kai Stian Olstad  

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

Reply all
Reply to author
Forward
0 new messages