Skip to content

Commit

Permalink
Test postrotate works
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jean-Philippe Evrard committed Aug 23, 2017
1 parent 3af4a3e commit 7b2cd66
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion defaults/main.yml
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions tasks/rsyslog_client_post_install.yml
Expand Up @@ -48,17 +48,20 @@
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:
- rsyslog_client-config

- 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

Expand Down
12 changes: 5 additions & 7 deletions tests/test.yml
Expand Up @@ -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
4 changes: 4 additions & 0 deletions vars/debian.yml
Expand Up @@ -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'
4 changes: 3 additions & 1 deletion vars/redhat-7.yml
Expand Up @@ -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: []
2 changes: 2 additions & 0 deletions vars/suse-42.yml
Expand Up @@ -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'

0 comments on commit 7b2cd66

Please sign in to comment.