From 4a11950728376c64bc075510fb4613adb55fcd71 Mon Sep 17 00:00:00 2001 From: Kishi85 Date: Mon, 3 Feb 2020 19:37:43 +0100 Subject: [PATCH] Update logrotate configs to preserve last 7 days --- roles/common/files/rsyslog | 37 ----------------------------------- roles/common/tasks/Debian.yml | 34 ++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 41 deletions(-) delete mode 100644 roles/common/files/rsyslog diff --git a/roles/common/files/rsyslog b/roles/common/files/rsyslog deleted file mode 100644 index 0cc2aa9..0000000 --- a/roles/common/files/rsyslog +++ /dev/null @@ -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 -} diff --git a/roles/common/tasks/Debian.yml b/roles/common/tasks/Debian.yml index 3c2a409..56c7610 100644 --- a/roles/common/tasks/Debian.yml +++ b/roles/common/tasks/Debian.yml @@ -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 }}"