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
This commit is contained in:
Jean-Philippe Evrard 2017-08-17 08:35:53 +00:00
parent 3af4a3e7a9
commit 7b2cd66e97
6 changed files with 20 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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: []

View File

@ -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'