MODULE FAILURE using Replace and with_together

107 views
Skip to first unread message

John Galts

unread,
Nov 28, 2016, 7:05:56 PM11/28/16
to Ansible Project
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 <module>
    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

John Galts

unread,
Nov 28, 2016, 7:05:57 PM11/28/16
to Ansible Project

Kai Stian Olstad

unread,
Nov 29, 2016, 10:45:42 AM11/29/16
to ansible...@googlegroups.com
On 28. nov. 2016 03:39, John Galts wrote:
> Hello, I'm getting a module failure when trying to use 'replace' and
> with_together.
> Is there something wrong with my script? thank you.

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

--
Kai Stian Olstad

Stankovic, Marko

unread,
Dec 1, 2016, 10:06:30 AM12/1/16
to ansible...@googlegroups.com
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


Cheers,

Marko


______________________________________________________________________________________________________

CONFIDENTIALITY NOTICE: This message is the property of International Game Technology PLC and/or
its subsidiaries and may contain proprietary, confidential or trade secret information.
This message is intended solely for the use of the addressee. If you are not the intended recipient
and have received this message in error, please delete this message from your system. Any unauthorized
reading, distribution, copying, or other use of this message or its attachments is strictly prohibited.

Stankovic, Marko

unread,
Dec 1, 2016, 10:15:39 AM12/1/16
to ansible...@googlegroups.com
I'm sorry, that was wrong solution.
Reply all
Reply to author
Forward
0 new messages