replace

Collection: builtin

Full Name: parallax.builtin.replace

Aliases: ansible.builtin.replace, replace

Synopsis

Replace every occurrence of a pattern in a file

Parameters

NameTypeRequiredDefaultDescription
pathstringyesPath to the file to modify
regexpstringyesRegular expression pattern to search for
replacestringReplacement string (if omitted, matching lines are removed)
backupboolfalseCreate a backup file including timestamp information
encodingstringutf-8encoding used for reading and writing the file
validatestringvalidate the file using a command
multilineboolfalseEnable multiline mode (^ and $ match line boundaries)
dotallboolfalseEnable dotall mode (. matches newlines)
ignorecaseboolfalseEnable case-insensitive matching
beforestringIf specified, only content before this pattern will be replaced
afterstringIf specified, only content after this pattern will be replaced
othersstringignoreignore, warn, or fail
ownerstringName of the user that should own the file
groupstringName of the group that should own the file
modestringThe permissions the resulting file should have
attributesstringThe attributes the resulting file should have
seuserstringThe user part of the SELinux file context
serolestringThe role part of the SELinux file context
setypestringThe type part of the SELinux file context
selevelstringThe level part of the SELinux file context
unsafe_writesboolfalseAllow unsafe file operations

Example

- name: Point every config at the new endpoint
  replace:
    path: /etc/app/app.conf
    regexp: "https://old\\.example\\.com"
    replace: https://new.example.com
    backup: true