2026-02-15 09:13:08 +01:00
|
|
|
---
|
|
|
|
|
- name: ram | Ensure Debian family
|
|
|
|
|
ansible.builtin.assert:
|
|
|
|
|
that: ansible_os_family == "Debian"
|
|
|
|
|
fail_msg: "This role only supports Debian/Proxmox systems."
|
|
|
|
|
|
2026-02-15 18:22:14 +01:00
|
|
|
- name: ram | Gather only memory fact
|
2026-02-15 18:18:57 +01:00
|
|
|
ansible.builtin.setup:
|
|
|
|
|
filter: ansible_memtotal_mb
|
|
|
|
|
|
2026-02-15 09:13:08 +01:00
|
|
|
- name: ram | Calculate log2ram size
|
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
|
log2ram_size_mb: >-
|
|
|
|
|
{{
|
2026-02-15 18:43:12 +01:00
|
|
|
[
|
|
|
|
|
log2ram_min_size_mb | int,
|
|
|
|
|
[
|
|
|
|
|
(ansible_memtotal_mb | int * log2ram_ram_percent | int / 100) | int,
|
|
|
|
|
log2ram_max_size_mb | int
|
|
|
|
|
] | min
|
2026-02-15 09:13:08 +01:00
|
|
|
] | 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:
|
2026-02-16 18:26:33 +01:00
|
|
|
url: https://github.com/azlux/log2ram/archive/refs/tags/1.7.2.tar.gz
|
2026-02-15 09:13:08 +01:00
|
|
|
dest: /tmp/log2ram.tar.gz
|
|
|
|
|
mode: '0644'
|
|
|
|
|
register: download_archive
|
|
|
|
|
|
2026-02-15 09:42:00 +01:00
|
|
|
- name: ram | Logic to extract and install log2ram
|
|
|
|
|
when: download_archive.changed # noqa: no-handler
|
2026-02-15 09:27:03 +01:00
|
|
|
block:
|
|
|
|
|
- name: ram | Extract log2ram
|
|
|
|
|
ansible.builtin.unarchive:
|
|
|
|
|
src: "/tmp/log2ram.tar.gz"
|
|
|
|
|
dest: "/tmp"
|
|
|
|
|
remote_src: yes
|
2026-02-15 09:13:08 +01:00
|
|
|
|
2026-02-15 09:27:03 +01:00
|
|
|
- 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
|
2026-02-15 09:13:08 +01:00
|
|
|
|
|
|
|
|
# Configure log2ram
|
|
|
|
|
|
2026-02-15 09:43:16 +01:00
|
|
|
- name: ram | Configure log2ram settings
|
2026-02-15 09:13:08 +01:00
|
|
|
ansible.builtin.lineinfile:
|
|
|
|
|
path: /etc/log2ram.conf
|
2026-02-15 09:42:00 +01:00
|
|
|
regexp: "{{ item.regexp }}"
|
|
|
|
|
line: "{{ item.line }}"
|
2026-02-15 09:13:08 +01:00
|
|
|
backup: yes
|
2026-02-15 09:42:00 +01:00
|
|
|
loop:
|
|
|
|
|
- { regexp: '^#?SIZE=', line: "SIZE={{ log2ram_size }}" }
|
|
|
|
|
- { regexp: '^#?USE_RSYNC=', line: "USE_RSYNC=true" }
|
2026-02-15 09:13:08 +01:00
|
|
|
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
|
2026-02-15 09:27:03 +01:00
|
|
|
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 }}" }
|