# Need to Replace single quote with double quotes in Ansible

**URL:** <https://forum.ansible.com/t/need-to-replace-single-quote-with-double-quotes-in-ansible/31124>\
**Category:** Ansible Project\
**Created:** [August 26, 2019, 9:03am UTC](https://forum.ansible.com/t/need-to-replace-single-quote-with-double-quotes-in-ansible/31124 "2019-08-26T09:03:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Easy\_King](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@Easy\_King](https://forum.ansible.com/u/Easy_King)\
**Post date:** [August 26, 2019, 9:03am UTC](https://forum.ansible.com/t/need-to-replace-single-quote-with-double-quotes-in-ansible/31124/1 "2019-08-26T09:03:05Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 26, 2019, 4:19pm UTC](https://forum.ansible.com/t/need-to-replace-single-quote-with-double-quotes-in-ansible/31124/2 "2019-08-26T16:19:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 26, 2019, 4:37pm UTC](https://forum.ansible.com/t/need-to-replace-single-quote-with-double-quotes-in-ansible/31124/3 "2019-08-26T16:37:09Z")

</div>

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
