refactor ♻️: Convert string to boolean for condition and changed_when #11

Merged
Jose merged 5 commits from dev into main 2026-02-14 08:45:14 +01:00
Showing only changes of commit 3be8cd10be - Show all commits

View File

@@ -6,18 +6,23 @@
state: present
reload: yes
- name: swap | Gather active swaps
command: swapon --noheadings --show=NAME
register: active_swaps
changed_when: false
- name: swap | Disable swap if host has enough RAM
ansible.builtin.command: swapoff -a
when:
- proxmox_disable_swap
- ansible_memtotal_mb >= proxmox_min_ram_mb_for_no_swap
changed_when: false
- active_swaps.stdout != ""
- name: swap | Remove swap from fstab
- name: swap | Comment swap entries in fstab
ansible.builtin.replace:
path: /etc/fstab
regexp: '^\S+\s+\S+\s+swap\s+.*$'
replace: ''
regexp: '^(\s*)(?!#)(\S+\s+\S+\s+swap\s+.*)$'
replace: '\1# \2'
Review

[Score: 3] Consider using an anchored regular expression to avoid potential false positives or unintended modifications. For example, use (?x)^(\s*)(?P<swap>^(\S+\s+\S+\s+swap\s.*))$ instead. This will ensure that only the swap lines are commented and not other lines containing 'swap'.

[Score: 3] Consider using an anchored regular expression to avoid potential false positives or unintended modifications. For example, use `(?x)^(\s*)(?P<swap>^(\S+\s+\S+\s+swap\s.*))$` instead. This will ensure that only the swap lines are commented and not other lines containing 'swap'.
when:
- proxmox_disable_swap
- ansible_memtotal_mb >= proxmox_min_ram_mb_for_no_swap