From f5718a354c15acd3a47424318de87b0aeeda1d53 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Thu, 4 Jun 2020 17:13:42 -0400 Subject: [PATCH] lineinfile - Add alternative backrefs example to docs (#69844) * lineinfile - Add alternative backrefs example to docs * Add changelog --- .../fragments/lineinfile-backrefs-syntax-example.yaml | 2 ++ lib/ansible/modules/lineinfile.py | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 changelogs/fragments/lineinfile-backrefs-syntax-example.yaml diff --git a/changelogs/fragments/lineinfile-backrefs-syntax-example.yaml b/changelogs/fragments/lineinfile-backrefs-syntax-example.yaml new file mode 100644 index 00000000000..9409b24d30c --- /dev/null +++ b/changelogs/fragments/lineinfile-backrefs-syntax-example.yaml @@ -0,0 +1,2 @@ +bugfixes: + - lineinfile - add example of using alternative backrefs syntax (https://github.com/ansible/ansible/issues/42794) diff --git a/lib/ansible/modules/lineinfile.py b/lib/ansible/modules/lineinfile.py index 2ffa8d74f1b..5860f4d6e73 100644 --- a/lib/ansible/modules/lineinfile.py +++ b/lib/ansible/modules/lineinfile.py @@ -200,6 +200,14 @@ EXAMPLES = r''' regexp: '^%ADMIN ALL=' line: '%ADMIN ALL=(ALL) NOPASSWD: ALL' validate: /usr/sbin/visudo -cf %s + +# See https://docs.python.org/3/library/re.html for further details on syntax +- name: Use backrefs with alternative group syntax to avoid conflicts with variable values + lineinfile: + path: /tmp/config + regexp: ^(host=).* + line: \g<1>{{ hostname }} + backrefs: yes ''' import os