From 7b2cd66e972e52e3e3acd0916badd41324d0f43d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Thu, 17 Aug 2017 08:35:53 +0000 Subject: [PATCH] Test postrotate works We should: - Not check what we do not set (kern.log and auth.log are already defined in rsyslog file, which we do not template). These two files would trigger an issue if both are in the same logrotate configuration. - Check that the rotation works, by forcing a rotation, and seeing that the new files are empty. Change-Id: I08357260e45919d9e71586cac6b9ce413adffc22 Closes-Bug: 1699875 Closes-Bug: 1709291 --- defaults/main.yml | 2 +- tasks/rsyslog_client_post_install.yml | 7 +++++-- tests/test.yml | 12 +++++------- vars/debian.yml | 4 ++++ vars/redhat-7.yml | 4 +++- vars/suse-42.yml | 2 ++ 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 49281cc..40a1cbf 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -61,7 +61,7 @@ rsyslog_client_log_rotate_options: - nocreate rsyslog_client_log_rotate_scripts: - name: postrotate - content: "restart rsyslog 2>&1 || true" + content: "{{ rsyslog_client_reload }}" # Set the `rsyslog_client_user_defined_targets` to define specific log targets. # This option will allow you to define multiple log targets with different templates diff --git a/tasks/rsyslog_client_post_install.yml b/tasks/rsyslog_client_post_install.yml index 8c4918a..ddee7c5 100644 --- a/tasks/rsyslog_client_post_install.yml +++ b/tasks/rsyslog_client_post_install.yml @@ -48,9 +48,12 @@ tags: - rsyslog_client-config +# The log files to handle/rotate are the files you can find +# in your log folder - the ones already defined for your +# distribution + the ones you decide to do manually - name: Union the log files set_fact: - rsyslog_client_all_log_files: "{{ log_files.files | map(attribute='path') | list | default([]) | union(rsyslog_client_log_files) }}" + rsyslog_client_all_log_files: "{{ log_files.files | map(attribute='path') | list | default([]) | union(rsyslog_client_log_files) | difference(rsyslog_client_already_handled_files) }}" when: - rsyslog_client_log_dir is defined tags: @@ -58,7 +61,7 @@ - name: Set rsyslog_client_all_log_files when log_files does not exist set_fact: - rsyslog_client_all_log_files: "{{ rsyslog_client_log_files }}" + rsyslog_client_all_log_files: "{{ rsyslog_client_log_files | difference(rsyslog_client_already_handled_files) }}" when: - rsyslog_client_log_dir is not defined diff --git a/tests/test.yml b/tests/test.yml index 6bc173b..c91e817 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -90,15 +90,13 @@ # check for log files that are explicitly defined in rsyslog_client_log_files - "'/var/log/dmesg' in logrotate_client_content" - "'/var/log/udev' in logrotate_client_content" - # check for a log file that should be discovered via rsyslog_client_log_dir - # /var/log/kern.log should exist on Ubuntu - # /var/log/yum.log should exist on CentOS - # /var/log/zypper.log should exist on openSUSE - - "'/var/log/kern.log' in logrotate_client_content - or '/var/log/yum.log' in logrotate_client_content - or '/var/log/zypper.log' in logrotate_client_content" - "'size 1G' in logrotate_client_content" - "rsyslog_default_file.stat.exists" - "rsyslog_remote_logging_conf.stat.exists" - "rsyslog_client_file.stat.exists" - "logrotate_file.stat.exists" + - name: Trigger postrotate to see if rotation can happen + command: logrotate -vf /etc/logrotate.conf + register: logrotation_output + tags: + - skip_ansible_lint diff --git a/vars/debian.yml b/vars/debian.yml index 0c5f35a..23ae6a5 100644 --- a/vars/debian.yml +++ b/vars/debian.yml @@ -21,4 +21,8 @@ rsyslog_client_distro_packages: - rsyslog - logrotate +rsyslog_client_already_handled_files: + - /var/log/kern.log + - /var/log/auth.log + rsyslog_client_reload: 'systemctl restart rsyslog > /dev/null 2>&1 || true' diff --git a/vars/redhat-7.yml b/vars/redhat-7.yml index 8f1d3d1..e563358 100644 --- a/vars/redhat-7.yml +++ b/vars/redhat-7.yml @@ -17,4 +17,6 @@ rsyslog_client_distro_packages: - rsyslog - logrotate -rsyslog_client_reload: '/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true' +rsyslog_client_reload: 'systemctl restart rsyslog 2>&1 || true' + +rsyslog_client_already_handled_files: [] diff --git a/vars/suse-42.yml b/vars/suse-42.yml index a3be4cb..90df292 100644 --- a/vars/suse-42.yml +++ b/vars/suse-42.yml @@ -20,4 +20,6 @@ rsyslog_client_distro_packages: rsyslog_client_distro_packages_remove: - systemd-logger # conflicts with rsyslog +rsyslog_client_already_handled_files: [] + rsyslog_client_reload: 'systemctl -q restart rsyslogd || true'