replace
Collection: builtin
Full Name: parallax.builtin.replace
Aliases: ansible.builtin.replace, replace
Synopsis
Replace every occurrence of a pattern in a file
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| path | string | yes | Path to the file to modify | |
| regexp | string | yes | Regular expression pattern to search for | |
| replace | string | Replacement string (if omitted, matching lines are removed) | ||
| backup | bool | false | Create a backup file including timestamp information | |
| encoding | string | utf-8 | encoding used for reading and writing the file | |
| validate | string | validate the file using a command | ||
| multiline | bool | false | Enable multiline mode (^ and $ match line boundaries) | |
| dotall | bool | false | Enable dotall mode (. matches newlines) | |
| ignorecase | bool | false | Enable case-insensitive matching | |
| before | string | If specified, only content before this pattern will be replaced | ||
| after | string | If specified, only content after this pattern will be replaced | ||
| others | string | ignore | ignore, warn, or fail | |
| owner | string | Name of the user that should own the file | ||
| group | string | Name of the group that should own the file | ||
| mode | string | The permissions the resulting file should have | ||
| attributes | string | The attributes the resulting file should have | ||
| seuser | string | The user part of the SELinux file context | ||
| serole | string | The role part of the SELinux file context | ||
| setype | string | The type part of the SELinux file context | ||
| selevel | string | The level part of the SELinux file context | ||
| unsafe_writes | bool | false | Allow 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