Documentation
PLEASE NOTE: This document applies to latest version and not to the latest stable release v2.21
Documentation for other releases can be found by using the version selector in the top right of any doc page.logrotate
Manage log rotation configurations.
Attributes
check_mode:
support: full
Parameters
| Parameter | Required | Type | Values | Description |
|---|---|---|---|---|
| path | true | Path to log file(s). Can be a single path or a list of paths. | ||
| state | string | present absent |
Whether the configuration should be present or absent. [default: "present"] |
|
| frequency | string | daily weekly monthly yearly |
How often to rotate logs. [default: "daily"] |
|
| rotate | integer | Number of rotated files to keep. | ||
| compress | boolean | Compress rotated log files. [default: false] |
||
| delaycompress | boolean | Delay compression until the next rotation cycle. [default: false] |
||
| missingok | boolean | Don’t report errors if log file is missing. [default: false] |
||
| notifempty | boolean | Don’t rotate empty log files. [default: false] |
||
| create | string | Create new log file after rotation with specified permissions. Format: mode owner group (e.g., “0644 root root”). | ||
| size | string | Rotate when file exceeds this size (e.g., “100M”, “1G”). | ||
| dateext | boolean | Use date as suffix for rotated files. [default: false] |
||
| dateformat | string | Format for date suffix (strftime format). | ||
| copy | boolean | Copy log file before truncating instead of moving. [default: false] |
||
| copytruncate | boolean | Truncate original log file in place instead of moving. [default: false] |
||
| sharedscripts | boolean | Don’t rotate if sharedscripts is set and the script fails. [default: false] |
||
| prerotate | string | Script to run before rotation. | ||
| postrotate | string | Script to run after rotation. | ||
| shared_scripts | boolean | Execute prerotate/postrotate scripts only once for all matched files. [default: false] |
||
| config_file | string | Custom configuration file path (default: /etc/logrotate.d/ |
Examples
- name: Configure log rotation for app
logrotate:
path: /var/log/app.log
frequency: daily
rotate: 7
compress: true
missingok: true
notifempty: true
- name: Configure log rotation for multiple log files
logrotate:
path:
- /var/log/app1.log
- /var/log/app2.log
frequency: weekly
rotate: 4
compress: true
delaycompress: true
- name: Configure log rotation with size limit
logrotate:
path: /var/log/large-app.log
size: 100M
rotate: 5
compress: true
- name: Remove log rotation configuration
logrotate:
path: /var/log/old-app.log
state: absent