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/003c497b-ccea-83e5-f4aa-7c44ae9a1a70%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to