From 6c1f43a4ccd9b956bd7d5ba9bc58f3d3dee4addf Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Tue, 5 Jul 2016 16:58:06 -0700 Subject: [PATCH] Allow overriding of default logrotate options Two variables have been added, rsyslog_client_log_rotate_options and rsyslog_client_log_rotate_scripts, to allow deployers to override and set logrotate config options as they wish. The os_aggregate_storage.j2 template has also been renamed to logrotate.j2 to better fit its purpose. Change-Id: If7538fd2409f3583f22209868f538e01796813c2 --- defaults/main.yml | 13 +++++++++++++ ...ient-logrotate-options-02dde942779493bb.yaml | 6 ++++++ tasks/rsyslog_client_post_install.yml | 2 +- templates/logrotate.j2 | 17 +++++++++++++++++ templates/os_aggregate_storage.j2 | 17 ----------------- tests/test.yml | 12 ++++++++++++ 6 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 releasenotes/notes/rsyslog-client-logrotate-options-02dde942779493bb.yaml create mode 100644 templates/logrotate.j2 delete mode 100644 templates/os_aggregate_storage.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 5a8ac6e..920580c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -42,6 +42,19 @@ rsyslog_client_tcp_port: 514 rsyslog_client_log_files: [] rsyslog_client_log_rotate_file: os_aggregate_storage +rsyslog_client_log_rotate_options: + - copytruncate + - weekly + - missingok + - rotate 14 + - compress + - dateext + - maxage 60 + - notifempty + - nocreate +rsyslog_client_log_rotate_scripts: + - name: postrotate + content: "restart rsyslog 2>&1 || true" # 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/releasenotes/notes/rsyslog-client-logrotate-options-02dde942779493bb.yaml b/releasenotes/notes/rsyslog-client-logrotate-options-02dde942779493bb.yaml new file mode 100644 index 0000000..8ebecc3 --- /dev/null +++ b/releasenotes/notes/rsyslog-client-logrotate-options-02dde942779493bb.yaml @@ -0,0 +1,6 @@ +--- +features: + - The options of application logrotate configuration files are now configurable. + ``rsyslog_client_log_rotate_options`` can be used to provide a list of directives, and + ``rsyslog_client_log_rotate_scripts`` can be used to provide a list of postrotate, prerotate, + firstaction, or lastaction scripts. diff --git a/tasks/rsyslog_client_post_install.yml b/tasks/rsyslog_client_post_install.yml index e054471..b038e21 100644 --- a/tasks/rsyslog_client_post_install.yml +++ b/tasks/rsyslog_client_post_install.yml @@ -54,7 +54,7 @@ - name: Write log rotate file template: - src: "os_aggregate_storage.j2" + src: "logrotate.j2" dest: "/etc/logrotate.d/{{ rsyslog_client_log_rotate_file }}" owner: "root" group: "root" diff --git a/templates/logrotate.j2 b/templates/logrotate.j2 new file mode 100644 index 0000000..4b13d05 --- /dev/null +++ b/templates/logrotate.j2 @@ -0,0 +1,17 @@ +{% for log_file in rsyslog_client_all_log_files %} +{{ log_file }} +{% endfor %} +{ +{% if rsyslog_client_log_rotate_options | length > 0 %} +{% for option in rsyslog_client_log_rotate_options %} + {{ option }} +{% endfor %} +{% endif %} +{% if rsyslog_client_log_rotate_scripts | length > 0 %} +{% for script in rsyslog_client_log_rotate_scripts %} + {{ script.name }} + {{ script.content }} + endscript +{% endfor %} +{% endif %} +} diff --git a/templates/os_aggregate_storage.j2 b/templates/os_aggregate_storage.j2 deleted file mode 100644 index 81a6b08..0000000 --- a/templates/os_aggregate_storage.j2 +++ /dev/null @@ -1,17 +0,0 @@ -{% for log_file in rsyslog_client_all_log_files %} -{{ log_file }} -{% endfor %} -{ - copytruncate - weekly - missingok - rotate 14 - compress - dateext - maxage 60 - notifempty - nocreate - postrotate - restart rsyslog 2>&1 || true - endscript -} diff --git a/tests/test.yml b/tests/test.yml index 10abd2e..6ba65ac 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -35,6 +35,17 @@ hostname: "logs-01.test.example.com" template: '$template LogglyFormat,"TESTING\n"' action_options: 'LogglyFormat' + rsyslog_client_log_rotate_options: + - copytruncate + - weekly + - missingok + - rotate 14 + - compress + - dateext + - maxage 60 + - notifempty + - nocreate + - size 1G post_tasks: - name: Open rsyslog client file slurp: @@ -69,6 +80,7 @@ - "'$ActionQueueFileName test-loggly1' in rsyslog_client_content" - "'/var/log/dmesg' in logrotate_client_content" - "'/var/log/udev' in logrotate_client_content" + - "'size 1G' in logrotate_client_content" - "rsyslog_default_file.stat.exists" - "rsyslog_client_file.stat.exists" - "logrotate_file.stat.exists"