From 6aaa186c1f149e34a0fb2acbc497a5c5e7f138f4 Mon Sep 17 00:00:00 2001 From: Jose Date: Sun, 15 Feb 2026 09:13:08 +0100 Subject: [PATCH 1/4] =?UTF-8?q?feat=20=E2=9C=A8:=20Add=20configuration=20o?= =?UTF-8?q?ptions=20for=20log2ram=20and=20journald=20settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces new features that allow users to configure log2ram and journald settings. It includes handlers for log2ram, journald, and a task to configure RAM usage. Additionally, a new role is added for installing and configuring log2ram on Debian systems. --- defaults/main.yml | 14 +++++++ handlers/main.yml | 14 +++++++ tasks/main.yml | 3 ++ tasks/ram.yml | 103 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 tasks/ram.yml diff --git a/defaults/main.yml b/defaults/main.yml index 3e2af6a..1c18c96 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -31,3 +31,17 @@ proxmox_apt_languages: - "en" - "es" - "it" + +# Percentage of total RAM to allocate to log2ram +log2ram_ram_percent: 10 + +log2ram_min_size_mb: 128 +log2ram_max_size_mb: 1024 + +# Journald RAM usage limit +journald_runtime_max_use: "100M" + +# VM write frequency tuning +vm_dirty_ratio: 15 +vm_dirty_background_ratio: 5 +vm_swappiness: "{{ proxmox_swapiness }}" diff --git a/handlers/main.yml b/handlers/main.yml index 44c8bd2..0c41bba 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -20,3 +20,17 @@ name: logrotate state: restarted become: true + +- name: Restart log2ram + ansible.builtin.systemd: + name: log2ram + state: restarted + enabled: yes + +- name: Restart journald + ansible.builtin.systemd: + name: systemd-journald + state: restarted + +- name: Reload sysctl + ansible.builtin.command: sysctl --system diff --git a/tasks/main.yml b/tasks/main.yml index 712fcb4..107d3b5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -39,3 +39,6 @@ - name: Configure kernel panic auto-reboot ansible.builtin.import_tasks: kernel.yml + +- name: Configure ram usage + ansible.builtin.import_tasks: ram.yml diff --git a/tasks/ram.yml b/tasks/ram.yml new file mode 100644 index 0000000..2dea592 --- /dev/null +++ b/tasks/ram.yml @@ -0,0 +1,103 @@ +--- +- name: ram | Ensure Debian family + ansible.builtin.assert: + that: ansible_os_family == "Debian" + fail_msg: "This role only supports Debian/Proxmox systems." + +- name: ram | Calculate log2ram size + ansible.builtin.set_fact: + _total_ram_mb: "{{ ansible_memtotal_mb }}" + _calculated_size_mb: "{{ (ansible_memtotal_mb * log2ram_ram_percent / 100) | int }}" + log2ram_size_mb: >- + {{ + [log2ram_min_size_mb, + [_calculated_size_mb, log2ram_max_size_mb] | min + ] | max + }} + +- name: ram | Convert size to M format + ansible.builtin.set_fact: + log2ram_size: "{{ log2ram_size_mb }}M" + +# - name: Install log2ram + +- name: ram | Install dependencies + ansible.builtin.apt: + name: + - rsync + - curl + - ca-certificates + state: present + update_cache: yes + cache_valid_time: 3600 # Only run apt-get update if it hasn't run in the last hour + +- name: ram | Download log2ram + ansible.builtin.get_url: + url: https://github.com/azlux/log2ram/archive/refs/heads/master.tar.gz + dest: /tmp/log2ram.tar.gz + # Adding a checksum ensures we only 'change' if the file is new/updated + checksum: "sha256:https://github.com/azlux/log2ram/archive/refs/heads/master.tar.gz.sha256" + mode: '0644' + register: download_archive + +- name: ram | Extract log2ram + ansible.builtin.unarchive: + src: "/tmp/log2ram.tar.gz" + dest: "/tmp" + remote_src: yes + when: download_archive.changed + +- name: ram | Install log2ram + ansible.builtin.command: bash install.sh + args: + chdir: "/tmp/log2ram-master" + # 'creates' makes the command idempotent by checking for the binary + creates: /usr/local/bin/log2ram + when: download_archive.changed + notify: Restart log2ram + +# Configure log2ram + +- name: ram | Configure log2ram size + ansible.builtin.lineinfile: + path: /etc/log2ram.conf + regexp: '^#?SIZE=' + line: "SIZE={{ log2ram_size }}" + backup: yes + notify: Restart log2ram + +- name: ram | Enable rsync sync + ansible.builtin.lineinfile: + path: /etc/log2ram.conf + regexp: '^#?USE_RSYNC=' + line: "USE_RSYNC=true" + notify: Restart log2ram + +# Keep journald fully in RAM + +- name: ram | Configure journald storage volatile + ansible.builtin.lineinfile: + path: /etc/systemd/journald.conf + regexp: '^#?Storage=' + line: "Storage=volatile" + backup: yes + notify: Restart journald + +- name: ram | Limit journald runtime size + ansible.builtin.lineinfile: + path: /etc/systemd/journald.conf + regexp: '^#?RuntimeMaxUse=' + line: "RuntimeMaxUse={{ journald_runtime_max_use }}" + notify: Restart journald + +# Enable log2ram on boot + +- name: ram | Configure memory tuning sysctl + ansible.builtin.copy: + dest: /etc/sysctl.d/99-proxmox-memory.conf + content: | + vm.swappiness = {{ vm_swappiness }} + vm.dirty_ratio = {{ vm_dirty_ratio }} + vm.dirty_background_ratio = {{ vm_dirty_background_ratio }} + mode: '0644' + notify: Reload sysctl -- 2.49.1 From 83febca09a5f39d8aaae06ccc8d4a97f882d6795 Mon Sep 17 00:00:00 2001 From: Jose Date: Sun, 15 Feb 2026 09:27:03 +0100 Subject: [PATCH 2/4] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Refactor?= =?UTF-8?q?=20task=20structure=20and=20update=20configuration=20method=20i?= =?UTF-8?q?n=20`ram.yml`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit refactors the task structure in `ram.yml` and updates the configuration method to improve readability and maintainability. --- handlers/main.yml | 3 --- tasks/ram.yml | 45 ++++++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 0c41bba..3932733 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -31,6 +31,3 @@ ansible.builtin.systemd: name: systemd-journald state: restarted - -- name: Reload sysctl - ansible.builtin.command: sysctl --system diff --git a/tasks/ram.yml b/tasks/ram.yml index 2dea592..e10d2be 100644 --- a/tasks/ram.yml +++ b/tasks/ram.yml @@ -40,21 +40,22 @@ mode: '0644' register: download_archive -- name: ram | Extract log2ram - ansible.builtin.unarchive: - src: "/tmp/log2ram.tar.gz" - dest: "/tmp" - remote_src: yes - when: download_archive.changed +- name: Installation Logic + block: + - name: ram | Extract log2ram + ansible.builtin.unarchive: + src: "/tmp/log2ram.tar.gz" + dest: "/tmp" + remote_src: yes -- name: ram | Install log2ram - ansible.builtin.command: bash install.sh - args: - chdir: "/tmp/log2ram-master" - # 'creates' makes the command idempotent by checking for the binary - creates: /usr/local/bin/log2ram + - name: ram | Install log2ram + ansible.builtin.command: bash install.sh + args: + chdir: "/tmp/log2ram-master" + # 'creates' makes the command idempotent by checking for the binary + creates: /usr/local/bin/log2ram + notify: Restart log2ram when: download_archive.changed - notify: Restart log2ram # Configure log2ram @@ -93,11 +94,13 @@ # Enable log2ram on boot - name: ram | Configure memory tuning sysctl - ansible.builtin.copy: - dest: /etc/sysctl.d/99-proxmox-memory.conf - content: | - vm.swappiness = {{ vm_swappiness }} - vm.dirty_ratio = {{ vm_dirty_ratio }} - vm.dirty_background_ratio = {{ vm_dirty_background_ratio }} - mode: '0644' - notify: Reload sysctl + ansible.posix.sysctl: + name: "{{ item.name }}" + value: "{{ item.value }}" + state: present + sysctl_file: /etc/sysctl.d/99-proxmox-memory.conf + reload: yes + loop: + - { name: 'vm.swappiness', value: "{{ vm_swappiness }}" } + - { name: 'vm.dirty_ratio', value: "{{ vm_dirty_ratio }}" } + - { name: 'vm.dirty_background_ratio', value: "{{ vm_dirty_background_ratio }}" } -- 2.49.1 From 7c664dfd4526ad1a72dca5adfe96bfd1763b9743 Mon Sep 17 00:00:00 2001 From: Jose Date: Sun, 15 Feb 2026 09:42:00 +0100 Subject: [PATCH 3/4] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Refactor?= =?UTF-8?q?=20installation=20logic=20and=20configure=20settings=20using=20?= =?UTF-8?q?loops?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This refactoring simplifies the installation process by utilizing loops to handle repetitive tasks, improving readability and maintainability of the code. --- tasks/ram.yml | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tasks/ram.yml b/tasks/ram.yml index e10d2be..b248910 100644 --- a/tasks/ram.yml +++ b/tasks/ram.yml @@ -40,7 +40,8 @@ mode: '0644' register: download_archive -- name: Installation Logic +- name: ram | Logic to extract and install log2ram + when: download_archive.changed # noqa: no-handler block: - name: ram | Extract log2ram ansible.builtin.unarchive: @@ -55,23 +56,18 @@ # 'creates' makes the command idempotent by checking for the binary creates: /usr/local/bin/log2ram notify: Restart log2ram - when: download_archive.changed # Configure log2ram -- name: ram | Configure log2ram size +- name: Configure log2ram settings ansible.builtin.lineinfile: path: /etc/log2ram.conf - regexp: '^#?SIZE=' - line: "SIZE={{ log2ram_size }}" + regexp: "{{ item.regexp }}" + line: "{{ item.line }}" backup: yes - notify: Restart log2ram - -- name: ram | Enable rsync sync - ansible.builtin.lineinfile: - path: /etc/log2ram.conf - regexp: '^#?USE_RSYNC=' - line: "USE_RSYNC=true" + loop: + - { regexp: '^#?SIZE=', line: "SIZE={{ log2ram_size }}" } + - { regexp: '^#?USE_RSYNC=', line: "USE_RSYNC=true" } notify: Restart log2ram # Keep journald fully in RAM -- 2.49.1 From 061f26aad59d170399609ff5bf1bb9f19a5663a3 Mon Sep 17 00:00:00 2001 From: Jose Date: Sun, 15 Feb 2026 09:43:16 +0100 Subject: [PATCH 4/4] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Rename=20t?= =?UTF-8?q?ask=20'Configure=20log2ram=20settings'=20to=20'ram=20|=20Config?= =?UTF-8?q?ure=20log2ram=20settings'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored the task name to include the 'ram' prefix for better clarity and consistency. --- tasks/ram.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/ram.yml b/tasks/ram.yml index b248910..366f592 100644 --- a/tasks/ram.yml +++ b/tasks/ram.yml @@ -59,7 +59,7 @@ # Configure log2ram -- name: Configure log2ram settings +- name: ram | Configure log2ram settings ansible.builtin.lineinfile: path: /etc/log2ram.conf regexp: "{{ item.regexp }}" -- 2.49.1