On Tue, 19 Jul 2022 at 19:31, Tony Wong <[email protected]> wrote:

> I keep getting errors when running an insert line task
>
> the task to insert is
>
> - name: add line
>   lineinfile:
>     backup: no
>     backrefs: yes
>     state: present
>     path: "{{ file_path }}"
>     regexp: '^(\s*)[#]?{{ item.search }}(: )*'
>     line: '\1{{ item.search }}\2\n\1{{ item.add }}'
>   with_items:
>     - { search: "{{ line.replace_with }}", add: "{{ line.line_to_add }}" }
>
> ------------------------------
>
> but I keep getting this error
>
>   File
> "/home/twong/.ansible/tmp/ansible-tmp-1658251625.2565749-23940-115530077073029/AnsiballZ_lineinfile.py",
> line 102, in <module>
>     _ansiballz_main()
>   File
> "/home/twong/.ansible/tmp/ansible-tmp-1658251625.2565749-23940-115530077073029/AnsiballZ_lineinfile.py",
> line 94, in _ansiballz_main
>     invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
>   File
> "/home/twong/.ansible/tmp/ansible-tmp-1658251625.2565749-23940-115530077073029/AnsiballZ_lineinfile.py",
> line 40, in invoke_module
>     runpy.run_module(mod_name='ansible.modules.lineinfile',
> init_globals=None, run_name='__main__', alter_sys=True)
>   File "/usr/lib64/python2.7/runpy.py", line 176, in run_module
>     fname, loader, pkg_name)
>   File "/usr/lib64/python2.7/runpy.py", line 82, in _run_module_code
>     mod_name, mod_fname, mod_loader, pkg_name)
>   File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
>     exec code in run_globals
>   File
> "/tmp/ansible_lineinfile_payload_D2ShX_/ansible_lineinfile_payload.zip/ansible/modules/lineinfile.py",
> line 577, in <module>
>   File
> "/tmp/ansible_lineinfile_payload_D2ShX_/ansible_lineinfile_payload.zip/ansible/modules/lineinfile.py",
> line 568, in main
>   File
> "/tmp/ansible_lineinfile_payload_D2ShX_/ansible_lineinfile_payload.zip/ansible/modules/lineinfile.py",
> line 342, in present
>   File "/usr/lib64/python2.7/re.py", line 266, in _expand
>     return sre_parse.expand_template(template, match)
>   File "/usr/lib64/python2.7/sre_parse.py", line 800, in expand_template
>     raise error, "unmatched group"
> sre_constants.error: unmatched group
> failed: [prod-soi-util-01w.activenetwork.com] (item={'search': '#image:
> jenkins/jenkins:2.346.1', 'add': 'image: jenkins/jenkins:2.346.2'}) => {
>     "ansible_loop_var": "item",
>     "changed": false,
>     "item": {
>         "add": "image: jenkins/jenkins:2.346.2",
>         "search": "#image: jenkins/jenkins:2.346.1"
>     },
>     "module_stderr": "OpenSSH_8.1p1, LibreSSL 2.7.3\r\ndebug1: Reading
> configuration data /Users/twong/.ssh/config\r\ndebug1:
> /Users/twong/.ssh/config line 1: Applying options for
> prod-soi-util-01w.activenetwork.com\r\ndebug1: Reading configuration data
> /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 47: Applying
> options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3
> setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version
> 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0
> remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3:
> mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive:
> done pid = 23846\r\ndebug3: mux_client_request_session: session request
> sent\r\ndebug3: mux_client_read_packet: read header failed: Broken
> pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to
> prod-soi-util-01w.activenetwork.com closed.\r\n",
>     "module_stdout": "Traceback (most recent call last):\r\n  File
> \"/home/twong/.ansible/tmp/ansible-tmp-1658251625.2565749-23940-115530077073029/AnsiballZ_lineinfile.py\",
> line 102, in <module>\r\n    _ansiballz_main()\r\n  File
> \"/home/twong/.ansible/tmp/ansible-tmp-1658251625.2565749-23940-115530077073029/AnsiballZ_lineinfile.py\",
> line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path,
> ANSIBALLZ_PARAMS)\r\n  File
> \"/home/twong/.ansible/tmp/ansible-tmp-1658251625.2565749-23940-115530077073029/AnsiballZ_lineinfile.py\",
> line 40, in invoke_module\r\n
>  runpy.run_module(mod_name='ansible.modules.lineinfile', init_globals=None,
> run_name='__main__', alter_sys=True)\r\n  File
> \"/usr/lib64/python2.7/runpy.py\", line 176, in run_module\r\n    fname,
> loader, pkg_name)\r\n  File \"/usr/lib64/python2.7/runpy.py\", line 82, in
> _run_module_code\r\n    mod_name, mod_fname, mod_loader, pkg_name)\r\n
>  File \"/usr/lib64/python2.7/runpy.py\", line 72, in _run_code\r\n    exec
> code in run_globals\r\n  File
> \"/tmp/ansible_lineinfile_payload_D2ShX_/ansible_lineinfile_payload.zip/ansible/modules/lineinfile.py\",
> line 577, in <module>\r\n  File
> \"/tmp/ansible_lineinfile_payload_D2ShX_/ansible_lineinfile_payload.zip/ansible/modules/lineinfile.py\",
> line 568, in main\r\n  File
> \"/tmp/ansible_lineinfile_payload_D2ShX_/ansible_lineinfile_payload.zip/ansible/modules/lineinfile.py\",
> line 342, in present\r\n  File \"/usr/lib64/python2.7/re.py\", line 266, in
> _expand\r\n    return sre_parse.expand_template(template, match)\r\n  File
> \"/usr/lib64/python2.7/sre_parse.py\", line 800, in expand_template\r\n
>  raise error, \"unmatched group\"\r\nsre_constants.error: unmatched
> group\r\n",
>

^^^

You expect the groups in your regex to always match, but clearly that isn't
the case.




>     "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
>     "rc": 1
> }
>
>
>
> any idea?
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/6d20b97c-c01e-4fe4-8df3-706f9df11be6n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/6d20b97c-c01e-4fe4-8df3-706f9df11be6n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
-- 
Sent from Gmail Mobile

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLY0-EL9NPQ7BH-NFtENBAJa9PBGTAkVYq7o4oiBWXbOMA%40mail.gmail.com.

Reply via email to