Need to Replace single quote with double quotes in Ansible

677 views
Skip to first unread message

Mohtashim S

unread,
Aug 26, 2019, 5:03:05 AM8/26/19
to Ansible Project
I have a multiline variable "filedet" that contains string text having multiple single quotes.

I wish to replace the single quote to double quotes so that It can be acceptable for SQL query and below is what I tried. 

    filedet: "{{ ( filedet ) | replace('/'','/'/'') }}"
    filedet: "{{ ( filedet ) | replace(''%c '%58'',''%c '%58''%c '%58'') }}"

It does not help. Can you please suggest ?

Dick Visser

unread,
Aug 26, 2019, 12:20:12 PM8/26/19
to ansible...@googlegroups.com
Is your string intended to be used as a value inside an SQL query?
Or is your string going to be the entire query?
And which SQL dialect are we talking about?

--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Dick Visser

unread,
Aug 26, 2019, 12:37:36 PM8/26/19
to ansible...@googlegroups.com
On Mon, 26 Aug 2019 at 18:19, Dick Visser <dick....@geant.org> wrote:
>
> On Mon, 26 Aug 2019 at 11:03, Mohtashim S <mohta...@gmail.com> wrote:
> >
> > I have a multiline variable "filedet" that contains string text having multiple single quotes.
> >
> > I wish to replace the single quote to double quotes so that It can be acceptable for SQL query and below is what I tried.
> >
> > filedet: "{{ ( filedet ) | replace('/'','/'/'') }}"
> > filedet: "{{ ( filedet ) | replace(''%c '%58'',''%c '%58''%c '%58'') }}"
> >
> > It does not help. Can you please suggest ?

I assume that "it does not help" means that you're getting an error.
It would have been nice to report that.
In any case, what you have now will result in a loop.

I you really must, you can replace the single quotes with double quotes by:

doubles: "{{ filedet | regex_replace(\"'\", '\"') }}"


Not sure why you're putting parentheses around the variable?


Dick
Reply all
Reply to author
Forward
0 new messages