replace module. Please explain \1 \2

15 views
Skip to first unread message

John Harmon

unread,
Sep 19, 2017, 5:19:36 PM9/19/17
to Ansible Project
I am trying to use the replace module, and I see all of these examples with \1 and \2 in them.  I assume these are for backrefs or soemthing?  Can someone explain it to me?  I am trying to append "sss" to my passwd and group lines in my nsswitch file.  I haven't tested my code yet, but I would still like to know what \1 \2 mean.  Maybe someone can point me to some documentation as I can't seem to find anything on it myself.

- 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" }


Gordon Messmer

unread,
Sep 19, 2017, 5:24:12 PM9/19/17
to Ansible Project
Yes, those appear to be regex back-references.  The documentation is here:

http://docs.ansible.com/ansible/latest/replace_module.html
Reply all
Reply to author
Forward
0 new messages