Kai Stian Olstad, thank you!  You are right, that worked. 
I tried my previous one at https://regex101.com/ and selected Python, but I 
guess it isn't 100% the same.  I will have to keep that in mind.

On Thursday, September 21, 2017 at 11:53:37 PM UTC-6, Kai Stian Olstad 
wrote:
>
> On 22. sep. 2017 01:08, John Harmon wrote: 
> > This works under a regexp tester, but fails under ansible.  I don't know 
> > how to correct it. 
>
> You need to use a Python based one, since Ansible is using Python re. 
>
>
> > Basically, it finds the lines starting with passwd or group, looks in 
> the 
> > lines for sss, and appends if it isn't found. 
> > 
> > - name: Update nsswitch.conf 
> >    replace: 
> >      path: /etc/nsswitch.conf 
> >      regexp: "{{item.regexp}}" 
> >      replace: "{{item.replace}}" 
> >    with_items: 
> >      - {regexp: '^(?:passwd):\s+(?:(?!sss).)+$', replace: '\0 sss'} 
> >      - {regexp: '^(?:group):\s+(?:(?!sss).)+$', replace: '\0 sss'} 
>
> \0 is interpreted as octal in Python re. 
>
> Try this instead 
>
>    - {regexp: '(^(?:passwd):\s+(?:(?!sss).)+$)', replace: '\1 sss'} 
>    - {regexp: '(^(?:group):\s+(?:(?!sss).)+$)', replace: '\1 sss'} 
>
> I added a parenthesis around the whole expression and references that as 
> \1 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/789ca263-5331-4f4b-b447-6ea295539359%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to