Skip to content

Commit 895667f

Browse files
jordanb-epccrichm
authored andcommitted
feat: Add MaxRetention configuration
Feature: Add variable to configure max retention parameter. Reason: Usually size-based deletion of the journal is sufficient with such options as `journald_max_disk_size` and `journald_max_files`, but in some cases time-based deletion is required in order to comply with data retention policies. Result: Users can configure journald MaxRetention. Signed-off-by: Rich Megginson <[email protected]>
1 parent f164878 commit 895667f

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ unless otherwise indicated.
7878
filling up.
7979
See `man 5 journald.conf` for more information
8080

81+
- `journald_max_retention` - integer variable, in minutes,
82+
sets how long journal entries can be retained before they are deleted.
83+
No implicit value is configured by the role.
84+
8185
## Example Playbook
8286

8387
```yaml

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ journald_forward_to_syslog: false
1111
journald_rate_limit_interval_sec: 30
1212
journald_rate_limit_burst: 10000
1313
journald_keep_free: 0
14+
journald_max_retention: 0

templates/journald.conf.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ Compress={{ journald_compression | bool | ternary("yes", "no") }}
4444
ForwardToSyslog={{ journald_forward_to_syslog | bool | ternary("yes", "no") }}
4545
RateLimitIntervalSec={{ journald_rate_limit_interval_sec }}s
4646
RateLimitBurst={{ journald_rate_limit_burst }}
47+
{% if journald_max_retention | int != 0 %}
48+
MaxRetentionSec={{ journald_max_retention }}m
49+
{% endif %}

tests/tasks/check_header.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
- name: Check for presence of ansible managed header, fingerprint
1010
assert:
1111
that:
12-
- ansible_managed in content
12+
- __ansible_managed in content
1313
- __fingerprint in content
1414
vars:
1515
content: "{{ (__file_content | d(__content)).content | b64decode }}"
16-
ansible_managed: "{{ lookup('template', 'get_ansible_managed.j2') }}"
16+
__ansible_managed: "{{ lookup('template', 'get_ansible_managed.j2') }}"

tests/tests_example.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
journald_rate_limit_burst: 2000
1212
journald_rate_limit_interval_sec: 2
1313
journald_keep_free: 10
14+
journald_max_retention: 30
1415
__service_files:
1516
- systemd-journald.service
1617
- systemd-journal-flush.service
@@ -88,13 +89,19 @@
8889
grep RateLimitBurst=2000
8990
"{{ __journald_dropin_dir }}/{{ __journald_dropin_conf }}"
9091
changed_when: false
91-
92+
9293
- name: Verify that system keep free is set properly
9394
command: >-
9495
grep SystemKeepFree=10
9596
"{{ __journald_dropin_dir }}/{{ __journald_dropin_conf }}"
9697
changed_when: false
9798

99+
- name: Verify that max retention is set properly
100+
command: >-
101+
grep MaxRetentionSec=30m
102+
"{{ __journald_dropin_dir }}/{{ __journald_dropin_conf }}"
103+
changed_when: false
104+
98105
- name: Verify that /var/log/journal/$MACHINE_ID/system.journal exists
99106
stat:
100107
path: /var/log/journal/{{ ansible_machine_id }}/system.journal

0 commit comments

Comments
 (0)