diff --git a/salt/states/file.py b/salt/states/file.py index 5e18cdf12d..84167da578 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -4501,6 +4501,22 @@ def replace(name, When using YAML multiline string syntax in ``pattern:``, make sure to also use that syntax in the ``repl:`` part, or you might loose line feeds. + + When regex capture groups are used in ``pattern:``, their captured value is + available for reuse in the ``repl:`` part as a backreference (ex. ``\1``). + + .. code-block:: yaml + + add_login_group_to_winbind_ssh_access_list: + file.replace: + - name: '/etc/security/pam_winbind.conf' + - pattern: '^(require_membership_of = )(.*)$' + - repl: '\1\2,append-new-group-to-line' + + .. note:: + + The ``file.replace`` state uses Python's ``re`` module. + For more advanced options, see https://docs.python.org/2/library/re.html ''' name = os.path.expanduser(name)