|
|
c99e83 |
From 8605fc4fd40f5d2067d9b81f41d5f523d9a5ba98 Mon Sep 17 00:00:00 2001
|
|
|
c99e83 |
From: Watson Sato <wsato@redhat.com>
|
|
|
c99e83 |
Date: Tue, 12 May 2020 08:17:20 +0200
|
|
|
c99e83 |
Subject: [PATCH 1/2] Add Ansible for ensure_logrotate_activated
|
|
|
c99e83 |
|
|
|
c99e83 |
---
|
|
|
c99e83 |
.../ansible/shared.yml | 33 +++++++++++++++++++
|
|
|
c99e83 |
1 file changed, 33 insertions(+)
|
|
|
c99e83 |
create mode 100644 linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/ansible/shared.yml
|
|
|
c99e83 |
|
|
|
c99e83 |
diff --git a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/ansible/shared.yml b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/ansible/shared.yml
|
|
|
c99e83 |
new file mode 100644
|
|
|
c99e83 |
index 0000000000..5d76b3c073
|
|
|
c99e83 |
--- /dev/null
|
|
|
c99e83 |
+++ b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/ansible/shared.yml
|
|
|
c99e83 |
@@ -0,0 +1,33 @@
|
|
|
c99e83 |
+# platform = multi_platform_all
|
|
|
c99e83 |
+# reboot = false
|
|
|
c99e83 |
+# strategy = configure
|
|
|
c99e83 |
+# complexity = low
|
|
|
c99e83 |
+# disruption = low
|
|
|
c99e83 |
+
|
|
|
c99e83 |
+- name: Configure daily log rotation in /etc/logrotate.conf
|
|
|
c99e83 |
+ lineinfile:
|
|
|
c99e83 |
+ create: yes
|
|
|
c99e83 |
+ dest: "/etc/logrotate.conf"
|
|
|
c99e83 |
+ regexp: "^daily$"
|
|
|
c99e83 |
+ line: "daily"
|
|
|
c99e83 |
+
|
|
|
c99e83 |
+- name: Make sure daily log rotation setting is not overriden in /etc/logrotate.conf
|
|
|
c99e83 |
+ lineinfile:
|
|
|
c99e83 |
+ create: no
|
|
|
c99e83 |
+ dest: "/etc/logrotate.conf"
|
|
|
c99e83 |
+ regexp: "^(weekly|monthly|yearly)$"
|
|
|
c99e83 |
+ state: absent
|
|
|
c99e83 |
+
|
|
|
c99e83 |
+- name: Configure cron.daily if not already
|
|
|
c99e83 |
+ block:
|
|
|
c99e83 |
+ - name: Add shebang
|
|
|
c99e83 |
+ lineinfile:
|
|
|
c99e83 |
+ path: "/etc/cron.daily/logrotate"
|
|
|
c99e83 |
+ line: "#!/bin/sh"
|
|
|
c99e83 |
+ insertbefore: BOF
|
|
|
c99e83 |
+ create: yes
|
|
|
c99e83 |
+ - name: Add logrotate call
|
|
|
c99e83 |
+ lineinfile:
|
|
|
c99e83 |
+ path: "/etc/cron.daily/logrotate"
|
|
|
c99e83 |
+ line: '/usr/sbin/logrotate /etc/logrotate.conf'
|
|
|
c99e83 |
+ regexp: '^[\s]*/usr/sbin/logrotate[\s\S]*/etc/logrotate.conf$'
|
|
|
c99e83 |
|
|
|
c99e83 |
From 085e5b2d18c9f50a6486a50f964ff71b74d5dade Mon Sep 17 00:00:00 2001
|
|
|
c99e83 |
From: Watson Sato <wsato@redhat.com>
|
|
|
c99e83 |
Date: Tue, 12 May 2020 14:48:15 +0200
|
|
|
c99e83 |
Subject: [PATCH 2/2] Add test for ensure_logrotate_activated
|
|
|
c99e83 |
|
|
|
c99e83 |
Test scenario when monthly is there, but weekly is not.
|
|
|
c99e83 |
---
|
|
|
c99e83 |
.../tests/logrotate_conf_extra_monthly.fail.sh | 4 ++++
|
|
|
c99e83 |
1 file changed, 4 insertions(+)
|
|
|
c99e83 |
create mode 100644 linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_conf_extra_monthly.fail.sh
|
|
|
c99e83 |
|
|
|
c99e83 |
diff --git a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_conf_extra_monthly.fail.sh b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_conf_extra_monthly.fail.sh
|
|
|
c99e83 |
new file mode 100644
|
|
|
c99e83 |
index 0000000000..b10362989b
|
|
|
c99e83 |
--- /dev/null
|
|
|
c99e83 |
+++ b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_conf_extra_monthly.fail.sh
|
|
|
c99e83 |
@@ -0,0 +1,4 @@
|
|
|
c99e83 |
+#!/bin/bash
|
|
|
c99e83 |
+
|
|
|
c99e83 |
+sed -i "s/weekly/daily/g" /etc/logrotate.conf
|
|
|
c99e83 |
+echo "monthly" >> /etc/logrotate.conf
|