feat ✨: Add configuration options for log2ram and journald settings #30
@@ -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 }}"
|
||||
|
||||
@@ -20,3 +20,14 @@
|
||||
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
|
||||
|
|
||||
|
||||
@@ -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
|
||||
|
gitea-actions
commented
[Lines 43-44] [Score: 2] Potential maintainability issue. Adding new tasks to an existing playbook without a clear reason or context may make the code less readable and harder to understand for other team members. It is recommended to keep the main playbook focused on high-level tasks, and delegate specific sub-tasks to separate files if necessary. [Lines 43-44] [Score: 2] Potential maintainability issue. Adding new tasks to an existing playbook without a clear reason or context may make the code less readable and harder to understand for other team members. It is recommended to keep the main playbook focused on high-level tasks, and delegate specific sub-tasks to separate files if necessary.
|
||||
|
||||
102
tasks/ram.yml
Normal file
@@ -0,0 +1,102 @@
|
||||
---
|
||||
|
gitea-actions
commented
[Score: 3] The YAML playbook starts with a single hyphen, which is a bad practice as it may lead to confusion or errors in interpreting the file. Use three hyphens instead (---). Context: Line 20: + log2ram_size: "{{ log2ram_size_mb }}M" Context: Line 57: + creates: /usr/local/bin/log2ram [Score: 3] The YAML playbook starts with a single hyphen, which is a bad practice as it may lead to confusion or errors in interpreting the file. Use three hyphens instead (---).
Context: Line 20: + log2ram_size: "{{ log2ram_size_mb }}M"
StartLine: 20
EndLine: 21
Comment: [Score: 2] Although not a critical issue, it is important to maintain consistency in naming conventions. Here, `log2ram_size` is defined in MB but the variable name does not explicitly indicate that it represents the size in Megabytes. Consider renaming this variable as `log2ram_size_in_mb`.
Context: Line 57: + creates: /usr/local/bin/log2ram
StartLine: 57
EndLine: 58
Comment: [Score: 3] Although the `creates` directive makes the command idempotent by checking for the binary, it might not be sufficient if you want to ensure that the command has been successfully installed and is executable. You may consider adding a check to verify the file's permissions and executability.
|
||||
- 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 | Logic to extract and install log2ram
|
||||
when: download_archive.changed # noqa: no-handler
|
||||
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
|
||||
notify: Restart log2ram
|
||||
|
||||
# Configure log2ram
|
||||
|
||||
- name: ram | Configure log2ram settings
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/log2ram.conf
|
||||
regexp: "{{ item.regexp }}"
|
||||
line: "{{ item.line }}"
|
||||
backup: yes
|
||||
loop:
|
||||
- { regexp: '^#?SIZE=', line: "SIZE={{ log2ram_size }}" }
|
||||
- { 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.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 }}" }
|
||||
[Lines 24-33] [Score: 3] Adding new handlers may require testing to ensure they don't interfere with existing functionality. Always consider maintainability and potential side effects when extending playbooks.