Skip to content

Commit

Permalink
Add support for prerotate script (robertdebock#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
danrough committed May 23, 2024
1 parent 6bb5c80 commit fba8e2e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tasks/assert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions templates/entry.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit fba8e2e

Please sign in to comment.