From 2f318448c5635e7a1e2309d4300e41e2b6c90042 Mon Sep 17 00:00:00 2001 From: teacup-on-rockingchair <315160+teacup-on-rockingchair@users.noreply.github.com> Date: Mon, 27 Apr 2026 08:39:21 +0300 Subject: [PATCH] Fix ensure_logrotate_activated to work with /etc configuration Make sure on sle16 we use /etc to apply and verify compliance to the rule, while /usr/etc maight be use only in case /etc files do not exist --- .../ensure_logrotate_activated/ansible/shared.yml | 5 ++--- .../ensure_logrotate_activated/bash/shared.sh | 7 ++++--- .../ensure_logrotate_activated/oval/shared.xml | 8 -------- .../tests/logrotate_conf_extra_monthly.fail.sh | 8 ++++++-- .../tests/logrotate_conf_weekly.fail.sh | 5 ++--- .../tests/logrotate_configured.pass.sh | 5 ++++- .../tests/logrotate_missing.fail.sh | 6 ++++++ .../tests/logrotate_no_config.fail.sh | 4 ++++ .../tests/logrotate_no_cron_daily_no_timer.fail.sh | 6 +++--- 9 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_missing.fail.sh 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 index e18fad5ddd4f..07a61ea4cab9 100644 --- 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 @@ -4,10 +4,9 @@ # complexity = low # disruption = low -{{% if product == 'sle16' %}} -{{% set LOGROTATE_CONF_FILE="/usr/etc/logrotate.conf" %}} -{{% else %}} {{% set LOGROTATE_CONF_FILE="/etc/logrotate.conf" %}} +{{% if product in [ 'sle16', 'slmicro6' ] %}} +{{{ ansible_copy_distro_defaults('/usr/etc/logrotate.conf', LOGROTATE_CONF_FILE, rule_title) }}} {{% endif %}} - name: "Configure daily log rotation in {{{ LOGROTATE_CONF_FILE }}}" diff --git a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/bash/shared.sh b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/bash/shared.sh index 82446d128faa..b6ca7b5f2188 100644 --- a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/bash/shared.sh +++ b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/bash/shared.sh @@ -1,10 +1,11 @@ # platform = multi_platform_all -{{% if product == 'sle16' %}} -LOGROTATE_CONF_FILE='/usr/etc/logrotate.conf' -{{% else %}} LOGROTATE_CONF_FILE='/etc/logrotate.conf' + +{{% if product in [ 'sle16', 'slmicro6' ] %}} +{{{ bash_copy_distro_defaults('/usr/etc/logrotate.conf', "${LOGROTATE_CONF_FILE}") }}} {{% endif %}} + {{% if 'sle' in product or product == 'slmicro5' %}} SYSTEMCTL_EXEC='/usr/bin/systemctl' {{% else %}} diff --git a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/oval/shared.xml b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/oval/shared.xml index 762e706a563d..fc8a7ba8688b 100644 --- a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/oval/shared.xml +++ b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/oval/shared.xml @@ -25,11 +25,7 @@ -{{% if product == 'sle16' %}} - /usr/etc/logrotate.conf -{{% else %}} /etc/logrotate.conf -{{% endif %}} ^\s*daily[\s#]*$ 1 @@ -41,11 +37,7 @@ -{{% if product == 'sle16' %}} - /usr/etc/logrotate.conf -{{% else %}} /etc/logrotate.conf -{{% endif %}} ^\s*(weekly|monthly|yearly)[\s#]*$ 1 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 index e7c626f5b93b..7a011c88bf4e 100644 --- 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 @@ -1,6 +1,10 @@ #!/bin/bash # packages = logrotate,crontabs +LOGROTATE_CONF_FILE="/etc/logrotate.conf" +{{% if product in [ 'sle16', 'slmicro6' ] %}} +{{{ bash_copy_distro_defaults('/usr/etc/logrotate.conf', "${LOGROTATE_CONF_FILE}") }}} +{{% endif %}} -sed -i "s/weekly/daily/g" /etc/logrotate.conf -echo "monthly" >> /etc/logrotate.conf +sed -i "s/weekly/daily/g" "${LOGROTATE_CONF_FILE}" +echo "monthly" >> "${LOGROTATE_CONF_FILE}" diff --git a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_conf_weekly.fail.sh b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_conf_weekly.fail.sh index 7e3bf2ae36ac..6d1132222642 100644 --- a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_conf_weekly.fail.sh +++ b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_conf_weekly.fail.sh @@ -1,8 +1,7 @@ #!/bin/bash -{{% if product == 'sle16' %}} -LOGROTATE_CONF_FILE="/usr/etc/logrotate.conf" -{{% else %}} LOGROTATE_CONF_FILE="/etc/logrotate.conf" +{{% if product in [ 'sle16', 'slmicro6' ] %}} +{{{ bash_copy_distro_defaults('/usr/etc/logrotate.conf', "${LOGROTATE_CONF_FILE}") }}} {{% endif %}} sed -i "s/daily/weekly/" "${LOGROTATE_CONF_FILE}" diff --git a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_configured.pass.sh b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_configured.pass.sh index 09409e4b3250..82e21f46cadc 100644 --- a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_configured.pass.sh +++ b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_configured.pass.sh @@ -1,7 +1,10 @@ #!/bin/bash -# platform = Oracle Linux 7,Oracle Linux 8 +# platform = Oracle Linux 7,Oracle Linux 8,SUSE Linux Enterprise 16 +{{% if product in [ 'sle16', 'slmicro6' ] %}} +{{{ bash_copy_distro_defaults('/usr/etc/logrotate.conf', '/etc/logrotate.conf') }}} +{{% endif %}} # fix logrotate config sed -i "s/\(weekly\|monthly\|yearly\)/daily/" /etc/logrotate.conf diff --git a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_missing.fail.sh b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_missing.fail.sh new file mode 100644 index 000000000000..ce29335f65ec --- /dev/null +++ b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_missing.fail.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# platform = SUSE Linux Enterprise 16 + +if [ -e "/etc/logrotate.conf" ] ; then + rm "/etc/logrotate.conf" +fi diff --git a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_no_config.fail.sh b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_no_config.fail.sh index dc8182483935..e17862f9bada 100644 --- a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_no_config.fail.sh +++ b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_no_config.fail.sh @@ -2,5 +2,9 @@ # packages = logrotate,crontabs +{{% if product in [ 'sle16', 'slmicro6' ] %}} +{{{ bash_copy_distro_defaults('/usr/etc/logrotate.conf', '/etc/logrotate.conf') }}} +{{% endif %}} + sed -i "/^\s*(daily|weekly|monthly|yearly)/d" /etc/logrotate.conf rm -f /etc/cron.daily/logrotate diff --git a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_no_cron_daily_no_timer.fail.sh b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_no_cron_daily_no_timer.fail.sh index 9ae01cc789bd..f01fb0aea345 100644 --- a/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_no_cron_daily_no_timer.fail.sh +++ b/linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/tests/logrotate_no_cron_daily_no_timer.fail.sh @@ -2,10 +2,10 @@ # packages = logrotate,crontabs -{{% if product == 'sle16' %}} -LOGROTATE_CONF_FILE="/usr/etc/logrotate.conf" -{{% else %}} LOGROTATE_CONF_FILE="/etc/logrotate.conf" + +{{% if product in [ 'sle16', 'slmicro6' ] %}} +{{{ bash_copy_distro_defaults('/usr/etc/logrotate.conf', "${LOGROTATE_CONF_FILE}") }}} {{% endif %}} # disable the timer