# MODULE FAILURE using Replace and with\_together

**URL:** <https://forum.ansible.com/t/module-failure-using-replace-and-with-together/23116>\
**Category:** Ansible Project\
**Created:** [November 28, 2016, 2:39am UTC](https://forum.ansible.com/t/module-failure-using-replace-and-with-together/23116 "2016-11-28T02:39:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Galts](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@John\_Galts](https://forum.ansible.com/u/John_Galts)\
**Post date:** [November 28, 2016, 2:39am UTC](https://forum.ansible.com/t/module-failure-using-replace-and-with-together/23116/1 "2016-11-28T02:39:59Z")

</div>

Hello, I’m getting a module failure when trying to use ‘replace’ and with\_together.  
Is there something wrong with my script? thank you.

Tasks:

- name: Gather Current DB Settings - Database Name  
shell: grep -v “|” /tmp/directory{{ date }}/{{ item }}/application/config/production/database.php | grep “‘database’” | awk ‘{print $3}’ | sed “s/  
;//g” | sed “s/'//g”  
with\_items:

- “{{ products }}”  
register: db\_name

- name: Update DB Settings - Database Name  
replace:  
dest: /tmp/directory{{ date }}/{{ item.0 }}/application/config/production/database.php  
regexp: ‘{{ item.1 }}’  
replace: ‘{{ item.2 }}’  
with\_together:

- “{{ products }}”

- db\_name.results

- “{{ database\_name\_update }}”

Error:

An exception occurred during task execution. The full traceback is:  
Traceback (most recent call last):  
File “/tmp/ansible\_DptbqW/ansible\_module\_replace.py”, line 169, in   
main()  
File “/tmp/ansible\_DptbqW/ansible\_module\_replace.py”, line 145, in main  
mre = re.compile(params[‘regexp’], re.MULTILINE)  
File “/usr/lib64/python2.7/re.py”, line 190, in compile  
return \_compile(pattern, flags)  
File “/usr/lib64/python2.7/re.py”, line 242, in \_compile  
raise error, v # invalid expression  
sre\_constants.error: unexpected end of regular expression

---

<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:** [November 29, 2016, 3:45pm UTC](https://forum.ansible.com/t/module-failure-using-replace-and-with-together/23116/2 "2016-11-29T15:45:01Z")

</div>

Since its failing with "unexpected end of regular expression" it impossible to say without the content of db\_name variable.

---

<div class="post-metadata">

**Author:** ![Stankovic\_Marko](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@Stankovic\_Marko](https://forum.ansible.com/u/Stankovic_Marko)\
**Post date:** [December 1, 2016, 3:06pm UTC](https://forum.ansible.com/t/module-failure-using-replace-and-with-together/23116/3 "2016-12-01T15:06:17Z")

</div>

Hi,

The last sed has an unescaped single quote.

You should replace this:

sed "s/'//g"

with this:

sed "s/"'"//g"

That's a single quote surrounded by double quotes. Backslash won't work.

You'll find some explanations here:

[http://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings](http://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings)

Cheers,

Marko

---

<div class="post-metadata">

**Author:** ![Stankovic\_Marko](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@Stankovic\_Marko](https://forum.ansible.com/u/Stankovic_Marko)\
**Post date:** [December 1, 2016, 3:15pm UTC](https://forum.ansible.com/t/module-failure-using-replace-and-with-together/23116/4 "2016-12-01T15:15:27Z")

</div>

I'm sorry, that was wrong solution.

Cheers,  
Marko
