From ddd69e04c00c2e695f06bc2cd89a8a2df0f30f63 Mon Sep 17 00:00:00 2001 From: Otthorn Date: Sat, 23 Jan 2021 14:25:35 +0100 Subject: [PATCH 01/12] create logrotate role --- roles/logrotate/handlers/main.yml | 5 +++ roles/logrotate/tasks/main.yml | 25 +++++++++++++ .../templates/logrotate.d/rsyslog.j2 | 37 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 roles/logrotate/handlers/main.yml create mode 100644 roles/logrotate/tasks/main.yml create mode 100644 roles/logrotate/templates/logrotate.d/rsyslog.j2 diff --git a/roles/logrotate/handlers/main.yml b/roles/logrotate/handlers/main.yml new file mode 100644 index 0000000..a58c62e --- /dev/null +++ b/roles/logrotate/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: reload logrotate + service: + name: logrotate + state: reloaded diff --git a/roles/logrotate/tasks/main.yml b/roles/logrotate/tasks/main.yml new file mode 100644 index 0000000..f6667b7 --- /dev/null +++ b/roles/logrotate/tasks/main.yml @@ -0,0 +1,25 @@ +--- +# Install and configure logrotate + +# Install the apt package +name: Install logrotate +apt: + name: + - logrotate + +# Copy the configuration and reload the service if it has changed +- name: Configure logrotate + template: + src: logrotate.d/rsyslog.j2 + dst: /etc/logrotate.d/rsyslog + owner: root + groupe: root + mode: "0644" + notify: restart logrotate + +# Make sure the service is enabled and started +- name: Enable logrotate service + service: + name: logrotate + enabled: true + state: started diff --git a/roles/logrotate/templates/logrotate.d/rsyslog.j2 b/roles/logrotate/templates/logrotate.d/rsyslog.j2 new file mode 100644 index 0000000..c304bb4 --- /dev/null +++ b/roles/logrotate/templates/logrotate.d/rsyslog.j2 @@ -0,0 +1,37 @@ +/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 1 + daily + missingok + notifempty + compress + delaycompress + sharedscripts + postrotate + /usr/lib/rsyslog/rsyslog-rotate + endscript +} From 05326c15d32a6b20c8f882434f07ee7011b3ea06 Mon Sep 17 00:00:00 2001 From: Otthorn Date: Sat, 23 Jan 2021 14:27:09 +0100 Subject: [PATCH 02/12] Enforce logrotate rules --- roles/logrotate/tasks/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/logrotate/tasks/main.yml b/roles/logrotate/tasks/main.yml index f6667b7..dd3a4d2 100644 --- a/roles/logrotate/tasks/main.yml +++ b/roles/logrotate/tasks/main.yml @@ -23,3 +23,7 @@ apt: name: logrotate enabled: true state: started + +# Enforce new logrotate rules now +- name: Run logrotate now + command: logrotate -f /etc/logrotate.d/rsyslog From 0122a293ebe146b4ca5f904162cfcfa3ba3a6a06 Mon Sep 17 00:00:00 2001 From: Otthorn Date: Sat, 23 Jan 2021 14:34:13 +0100 Subject: [PATCH 03/12] Add the unify group --- hosts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hosts b/hosts index a06cac8..90d248e 100644 --- a/hosts +++ b/hosts @@ -445,6 +445,13 @@ edc_pve gs_pve rives_pve +# every unifi +[unifi] +gs_unifi +edc_unifi +fleming_unifi +rives_unifi +pacaterie_unifi ############################################################################### # Groups by service From 0d9fd160302057fac8ad0bc987f40e111ff8844f Mon Sep 17 00:00:00 2001 From: Otthorn Date: Sat, 23 Jan 2021 14:35:03 +0100 Subject: [PATCH 04/12] Add logrotate to the base playbook --- base.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/base.yml b/base.yml index 5aee2d2..1ea1901 100755 --- a/base.yml +++ b/base.yml @@ -10,3 +10,8 @@ - hosts: all,!unifi roles: - ldap_client + +# Install logrotate +- hosts: all,!unifi,!pve:children + roles: + - logrotate From 66c2ff63053c72e93e7197f2c9ffef8015706161 Mon Sep 17 00:00:00 2001 From: Otthorn Date: Sat, 23 Jan 2021 14:37:18 +0100 Subject: [PATCH 05/12] full path to logrotate for command --- roles/logrotate/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/logrotate/tasks/main.yml b/roles/logrotate/tasks/main.yml index dd3a4d2..8e78e90 100644 --- a/roles/logrotate/tasks/main.yml +++ b/roles/logrotate/tasks/main.yml @@ -26,4 +26,4 @@ apt: # Enforce new logrotate rules now - name: Run logrotate now - command: logrotate -f /etc/logrotate.d/rsyslog + command: /usr/sbin/logrotate -f /etc/logrotate.d/rsyslog From 43274ef2ec8d57cc6b25333f49a47662f146ae3e Mon Sep 17 00:00:00 2001 From: Otthorn Date: Sat, 23 Jan 2021 14:40:29 +0100 Subject: [PATCH 06/12] Add the ansible_managed var at the begining of the config file --- roles/logrotate/templates/logrotate.d/rsyslog.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/logrotate/templates/logrotate.d/rsyslog.j2 b/roles/logrotate/templates/logrotate.d/rsyslog.j2 index c304bb4..beab470 100644 --- a/roles/logrotate/templates/logrotate.d/rsyslog.j2 +++ b/roles/logrotate/templates/logrotate.d/rsyslog.j2 @@ -1,3 +1,5 @@ +# {{ ansible_managed }} + /var/log/syslog { rotate 7 From 73142dbe03210e1cc5ec1cbc291b2d3669107037 Mon Sep 17 00:00:00 2001 From: Otthorn Date: Sat, 23 Jan 2021 14:41:25 +0100 Subject: [PATCH 07/12] Fix yaml syntax --- roles/logrotate/tasks/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/roles/logrotate/tasks/main.yml b/roles/logrotate/tasks/main.yml index 8e78e90..81fc7ed 100644 --- a/roles/logrotate/tasks/main.yml +++ b/roles/logrotate/tasks/main.yml @@ -2,10 +2,10 @@ # Install and configure logrotate # Install the apt package -name: Install logrotate -apt: - name: - - logrotate +- name: Install logrotate + apt: + name: + - logrotate # Copy the configuration and reload the service if it has changed - name: Configure logrotate From d50288ccffbaa4925ed6aa63d26fd0161df642bd Mon Sep 17 00:00:00 2001 From: Solal Nathan Date: Sat, 23 Jan 2021 15:12:28 +0100 Subject: [PATCH 08/12] fix host syntax --- base.yml | 2 +- hosts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base.yml b/base.yml index 1ea1901..38ec360 100755 --- a/base.yml +++ b/base.yml @@ -12,6 +12,6 @@ - ldap_client # Install logrotate -- hosts: all,!unifi,!pve:children +- hosts: all,!unifi,!pve roles: - logrotate diff --git a/hosts b/hosts index 90d248e..98a435e 100644 --- a/hosts +++ b/hosts @@ -446,7 +446,7 @@ gs_pve rives_pve # every unifi -[unifi] +[unifi:children] gs_unifi edc_unifi fleming_unifi From e1a961273df956ae0c53d0e54dcd12903d040c62 Mon Sep 17 00:00:00 2001 From: Solal Nathan Date: Sat, 23 Jan 2021 15:42:52 +0100 Subject: [PATCH 09/12] fix typo: dst -> dest --- roles/logrotate/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/logrotate/tasks/main.yml b/roles/logrotate/tasks/main.yml index 81fc7ed..b786ba0 100644 --- a/roles/logrotate/tasks/main.yml +++ b/roles/logrotate/tasks/main.yml @@ -11,7 +11,7 @@ - name: Configure logrotate template: src: logrotate.d/rsyslog.j2 - dst: /etc/logrotate.d/rsyslog + dest: /etc/logrotate.d/rsyslog owner: root groupe: root mode: "0644" From e6af0f2bd74c890e053f3bc567236089babfc647 Mon Sep 17 00:00:00 2001 From: Solal Nathan Date: Sat, 23 Jan 2021 15:59:03 +0100 Subject: [PATCH 10/12] fix typo: groupe -> group --- roles/logrotate/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/logrotate/tasks/main.yml b/roles/logrotate/tasks/main.yml index b786ba0..e9ba3a1 100644 --- a/roles/logrotate/tasks/main.yml +++ b/roles/logrotate/tasks/main.yml @@ -13,7 +13,7 @@ src: logrotate.d/rsyslog.j2 dest: /etc/logrotate.d/rsyslog owner: root - groupe: root + group: root mode: "0644" notify: restart logrotate From 795ee3846fa98377604abb5505ab204e1eac80fc Mon Sep 17 00:00:00 2001 From: Solal Nathan Date: Sat, 23 Jan 2021 16:02:10 +0100 Subject: [PATCH 11/12] fix indent --- roles/logrotate/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/logrotate/tasks/main.yml b/roles/logrotate/tasks/main.yml index e9ba3a1..656a746 100644 --- a/roles/logrotate/tasks/main.yml +++ b/roles/logrotate/tasks/main.yml @@ -15,7 +15,7 @@ owner: root group: root mode: "0644" - notify: restart logrotate + notify: restart logrotate # Make sure the service is enabled and started - name: Enable logrotate service From fff6ec5807ed6ea998799c9cecfef81a8d6b2374 Mon Sep 17 00:00:00 2001 From: Solal Nathan Date: Sat, 23 Jan 2021 16:04:09 +0100 Subject: [PATCH 12/12] fix typo: restart -> reload --- roles/logrotate/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/logrotate/tasks/main.yml b/roles/logrotate/tasks/main.yml index 656a746..e76b591 100644 --- a/roles/logrotate/tasks/main.yml +++ b/roles/logrotate/tasks/main.yml @@ -15,7 +15,7 @@ owner: root group: root mode: "0644" - notify: restart logrotate + notify: reload logrotate # Make sure the service is enabled and started - name: Enable logrotate service