From fba8e2edc2e7bd5a4f2547b3b207d5a5995b4179 Mon Sep 17 00:00:00 2001 From: Dan Rough Date: Thu, 23 May 2024 21:33:42 +0100 Subject: [PATCH] Add support for prerotate script (#22) --- README.md | 5 ++++- molecule/default/converge.yml | 5 ++++- tasks/assert.yml | 12 ++++++++++++ templates/entry.j2 | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b814897..9a83041 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,10 @@ This example is taken from [`molecule/default/converge.yml`](https://github.com/ - name: example-delaycompress path: "/var/log/example-delaycompress/*.log" delaycompress: true - - name: example-script + - name: example-prerotate-script + path: "/var/log/example-script/*.log" + prerotate: echo "e.g. backup to an offsite location" + - name: example-postrotate-script path: "/var/log/example-script/*.log" postrotate: killall -HUP some_process_name - name: btmp diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 2af0cca..7a35e3c 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -29,7 +29,10 @@ - name: example-delaycompress path: "/var/log/example-delaycompress/*.log" delaycompress: true - - name: example-script + - name: example-prerotate-script + path: "/var/log/example-script/*.log" + prerotate: echo "e.g. backup to an offsite location" + - name: example-postrotate-script path: "/var/log/example-script/*.log" postrotate: killall -HUP some_process_name - name: btmp diff --git a/tasks/assert.yml b/tasks/assert.yml index 26e4677..65fce4d 100644 --- a/tasks/assert.yml +++ b/tasks/assert.yml @@ -127,6 +127,18 @@ when: - item.delaycompress is defined +- name: assert | Test prerotate in logrotate_entries + ansible.builtin.assert: + that: + - item.prerotate is string + - item.prerotate is not none + quiet: true + loop: "{{ logrotate_entries }}" + loop_control: + label: "{{ item.name }}" + when: + - item.prerotate is defined + - name: assert | Test postrotate in logrotate_entries ansible.builtin.assert: that: diff --git a/templates/entry.j2 b/templates/entry.j2 index 016179c..e17e99b 100644 --- a/templates/entry.j2 +++ b/templates/entry.j2 @@ -34,6 +34,10 @@ {% if item.dateyesterday is defined and item.dateyesterday %} dateyesterday{% endif %} +{% if item.prerotate is defined %} prerotate + {{ item.prerotate }} + endscript{% endif %} + {% if item.postrotate is defined %} postrotate {{ item.postrotate }} endscript{% endif %}