You haven't actually created a match group in your regex. I assume you want something like ^(group.*) or something. The () create the match group.
On Thu, Sep 21, 2017 at 1:13 PM, John Harmon <[email protected]> wrote: > I am trying to append to some lines within the nsswitch file to setup > sssd. I am trying this with the loop below, but I have never used backrefs > before. I am unsure if I am doing it correctly. I get an error about an > invalid group reference. I wonder if my regexp is wrong? > > Code > - name: Update nsswitch.conf > replace: > path: /etc/nsswitch.conf > regexp: "{{item.regexp}}" > replace: "{{item.replace}}" > with_items: > - {regexp: '^passwd.*', > replace: '\1 sss'} > - {regexp: '^group.*', > replace: '\1 sss'} > notify: restart sssd > > Traceback results > > The full traceback is: > Traceback (most recent call last): > File "/tmp/ansible_q0xtoH/ansible_module_replace.py", line 200, in > <module> > main() > File "/tmp/ansible_q0xtoH/ansible_module_replace.py", line 173, in main > result = re.subn(mre, params['replace'], contents, 0) > File "/usr/lib64/python2.6/re.py", line 162, in subn > return _compile(pattern, 0).subn(repl, string, count) > File "/usr/lib64/python2.6/re.py", line 278, in filter > return sre_parse.expand_template(template, match) > File "/usr/lib64/python2.6/sre_parse.py", line 795, in expand_template > raise error, "invalid group reference" > sre_constants.error: invalid group reference > > failed: [ansibletest-oel6] (item={u'regexp': u'^group.*', u'replace': u'\\1 > sss'}) => { > "failed": true, > "item": { > "regexp": "^group.*", > "replace": "\\1 sss" > }, > "module_stderr": "Traceback (most recent call last):\n File > \"/tmp/ansible_q0xtoH/ansible_module_replace.py\", line 200, in > <module>\n main()\n File > \"/tmp/ansible_q0xtoH/ansible_module_replace.py\", > line 173, in main\n result = re.subn(mre, params['replace'], contents, > 0)\n File \"/usr/lib64/python2.6/re.py\", line 162, in subn\n return > _compile(pattern, 0).subn(repl, string, count)\n File > \"/usr/lib64/python2.6/re.py\", line 278, in filter\n return > sre_parse.expand_template(template, match)\n File > \"/usr/lib64/python2.6/sre_parse.py\", line 795, in expand_template\n > raise error, \"invalid group reference\"\nsre_constants.error: invalid > group reference\n", > "module_stdout": "", > "msg": "MODULE FAILURE", > "rc": 1 > } > > > -- > 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 post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/ansible-project/4d26cef9-107d-4f41-967e-dcb52328491b%40googlegroups. > com > <https://groups.google.com/d/msgid/ansible-project/4d26cef9-107d-4f41-967e-dcb52328491b%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Matt Martz @sivel sivel.net -- 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 post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAD8N0v9%3D2x1VOumAp5mHgr5_pteZ81t18zLTHw2_orna0ALftA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
