How to escape single quote in regex_replace expression?

218 views
Skip to first unread message

Veena

unread,
Aug 22, 2018, 8:00:45 AM8/22/18
to Ansible Project
Hi,

I'm using Ansible 2.5 and trying to escape single quote in a string. This string will be passed as argument to shell command. 

regex_replace("'", "\'") is giving error. 

    - set_fact:

       default_passphrase: "{{ Secrete123'!#) | regex_replace('"'"', '"\'"') }}" 

Please suggest how to achieve this. 

Thanks,
-Veena

Jean-Yves LENHOF

unread,
Aug 22, 2018, 8:11:58 AM8/22/18
to ansible...@googlegroups.com, Veena
> --
> 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-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/d4d5b7b0-3ee9-49c9-bdcd-cc13cac7cb30%40googlegroups.com
> [1].
> For more options, visit https://groups.google.com/d/optout.
>
>
> Links:
> ------
> [1]
> https://groups.google.com/d/msgid/ansible-project/d4d5b7b0-3ee9-49c9-bdcd-cc13cac7cb30%40googlegroups.com?utm_medium=email&utm_source=footer

Hi,

Did you try with the quote filter ?

Regards,

JYL

Veena

unread,
Aug 22, 2018, 8:31:55 AM8/22/18
to Ansible Project
quote filter also didn't work. Got the below error

template error while templating string: unexpected char u\"'\"

Jean-Yves LENHOF

unread,
Aug 22, 2018, 10:05:23 AM8/22/18
to ansible...@googlegroups.com, Veena
Le 2018-08-22 14:00, Veena a écrit :
What do you want to do ?
Perhaps set a specific default password

Did you try this ?

Veena

unread,
Aug 22, 2018, 10:11:48 AM8/22/18
to Ansible Project
I'm just trying with a dummy password. In the actual use case, the value will be read from config file which will be generated after user sets password. So I need to first get the password value in the 1st task and then set_fact, further use it in the shell command. I don't want to block the customer from using any special character. 
Reply all
Reply to author
Forward
0 new messages