Update logrotate configs to preserve last 7 days

This commit is contained in:
Kishi85 2020-02-03 19:37:43 +01:00
parent 786ecd554f
commit 4a11950728
2 changed files with 30 additions and 41 deletions

View File

@ -1,37 +0,0 @@
/var/log/syslog
{
rotate 7
daily
missingok
notifempty
delaycompress
compress
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}
/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
{
rotate 7
daily
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}

View File

@ -64,7 +64,33 @@
line: "MaxRetentionSec=7day"
notify: Restart journald
- name: Configure log retention
copy: src={{ item }} dest=/etc/logrotate.d/{{ item }}
with_items:
- rsyslog
- name: Set logrotate.conf to daily
replace:
path: "/etc/logrotate.conf"
regexp: "(?:weekly|monthly)"
replace: "daily"
- name: Set logrotate.conf rotation to 7
replace:
path: "/etc/logrotate.conf"
regexp: "rotate [0-9]+"
replace: "rotate 7"
- name: Find logrotate.d configuration files
find:
paths: "/etc/logrotate.d/"
register: "logrotateconfigs"
- name: Set logrotate.d/* to daily
replace:
path: "{{ item }}"
regexp: "(?:weekly|monthly)"
replace: "daily"
loop: "{{ logrotateconfigs.files }}"
- name: Set logrotate.conf rotation to 7
replace:
path: "{{ item }}"
regexp: "rotate [0-9]+"
replace: "rotate 7"
loop: "{{ logrotateconfigs.files }}"