From fd04a750a587d0be54a806f553948ac3008b5ed4 Mon Sep 17 00:00:00 2001 From: Kishi85 Date: Tue, 4 Feb 2020 15:01:13 +0100 Subject: [PATCH] Add excludes to logrotate.d config and update to correct paths --- roles/common/defaults/main.yml | 8 ++++++++ roles/common/tasks/Debian.yml | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 roles/common/defaults/main.yml diff --git a/roles/common/defaults/main.yml b/roles/common/defaults/main.yml new file mode 100644 index 0000000..83d6fca --- /dev/null +++ b/roles/common/defaults/main.yml @@ -0,0 +1,8 @@ +--- +logrotate_excludes: +- "/etc/logrotate.d/alternatives" +- "/etc/logrotate.d/apt" +- "/etc/logrotate.d/dpkg" +- "/etc/logrotate.d/dbconfig-common" +- "/etc/logrotate.d/btmp" +- "/etc/logrotate.d/wtmp" diff --git a/roles/common/tasks/Debian.yml b/roles/common/tasks/Debian.yml index 56c7610..4038343 100644 --- a/roles/common/tasks/Debian.yml +++ b/roles/common/tasks/Debian.yml @@ -81,16 +81,24 @@ paths: "/etc/logrotate.d/" register: "logrotateconfigs" -- name: Set logrotate.d/* to daily +- name: Convert found files to path list + set_fact: + alllogrotateconfigpaths: "{{ logrotateconfigs.files | map(attribute='path') | list }}" + +- name: Exclude files from ansible management + set_fact: + logrotateconfigpaths: "{{ alllogrotateconfigpaths | difference(logrotate_excludes) }}" + +- name: 'Set logrotate.d/* to daily' replace: path: "{{ item }}" regexp: "(?:weekly|monthly)" replace: "daily" - loop: "{{ logrotateconfigs.files }}" + loop: "{{ logrotateconfigpaths }}" -- name: Set logrotate.conf rotation to 7 +- name: 'Set /etc/logrotate.d/* rotation to 7' replace: path: "{{ item }}" regexp: "rotate [0-9]+" replace: "rotate 7" - loop: "{{ logrotateconfigs.files }}" + loop: "{{ logrotateconfigpaths }}"