commit 6c799f6dbccc272eed6f4446e12368e84177f10a Author: Sven Velt Date: Fri Nov 8 11:24:44 2024 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a204212 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.*.swp +*~ + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a6da0a6 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# systemd-journald-size + +Set maximum disk usage for systemd-journald + +## Requirements + +- systemd based Linux distribution with systemd-journald + +## Role Variables + +Defaults: +- `systemd_journald_size`: `100M` + +## Dependencies + +- None + +## Example Playbook + + - hosts: all + roles: + - role: systemd-journald-size + when: ansible_service_mgr == 'systemd' + + +## License + +AGPL3.0-or-later + +## Author Information + +- Sven Velt +- https://git.velt.biz/ + + diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..caa4a8e --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,3 @@ +--- +systemd_journald_size: 100M + diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..9506117 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,10 @@ +--- +- name: Restart systemd-journald + service: + name: systemd-journald + state: restarted + +- name: Vaccuum journald + command: + cmd: 'journalctl --vacuum-size={{ systemd_journald_size }}' + diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..efea4cb --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,39 @@ +galaxy_info: + author: Sven Velt + description: Set maximum disk usage of systemd-journald + company: velt.biz + issue_tracker_url: https://git.velt.biz/Ansible/systemd-journald-size/issues + license: AGPL-3.0-or-later + min_ansible_version: 2.1 + platforms: + - name: Debian + versions: + - stretch + - buster + - bullseye + - bookworm + - trixie + - name: Ubuntu + versions: + - bionic + - focal + - jammy + - noble + - name: Fedora + versions: + - 38 + - 39 + - 40 + - 41 + - name: EL + versions: + - 6 + - 7 + - 8 + - 9 + + galaxy_tags: + - operations + +dependencies: [] + diff --git a/systemd-journald-size.yml b/systemd-journald-size.yml new file mode 100644 index 0000000..091f490 --- /dev/null +++ b/systemd-journald-size.yml @@ -0,0 +1,7 @@ +--- +- hosts: all + + roles: + - role: systemd-journald-size + when: ansible_service_mgr == 'systemd' + diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..32c05a5 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: Check if systemd-journald is running + service_facts: + ignore_errors: true + register: systemd_journald_services + +- name: '[BLOCK] When systemd-journald is running...' + when: systemd_journald_services is succeeded and "systemd-journald.service" in ansible_facts.services + block: + + - name: Create /etc/systemd/journald.conf.d + file: + path: /etc/systemd/journald.conf.d + state: directory + owner: root + group: root + mode: 0755 + + - name: Template /etc/systemd/journald.conf.d/SystemMaxUse.conf + template: + src: SystemMaxUse.conf.j2 + dest: /etc/systemd/journald.conf.d/SystemMaxUse.conf + owner: root + group: root + mode: 0755 + backup: true + notify: + - Restart systemd-journald + - Vaccuum journald + diff --git a/templates/SystemMaxUse.conf.j2 b/templates/SystemMaxUse.conf.j2 new file mode 100644 index 0000000..7679699 --- /dev/null +++ b/templates/SystemMaxUse.conf.j2 @@ -0,0 +1,2 @@ +[Journal] +SystemMaxUse={{ systemd_journald_size }}