From 3be8cd10be9616363a0a6d40cabe5df67ceefa02 Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 12 Feb 2026 21:29:59 +0100 Subject: [PATCH] =?UTF-8?q?feat=20=E2=9C=A8:=20Add=20task=20to=20gather=20?= =?UTF-8?q?active=20swaps=20and=20comment=20swap=20entries=20in=20fstab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces a new feature that adds a task to gather information about active swaps on the system. Additionally, it comments out existing swap entries in the `/etc/fstab` file to prevent them from being mounted at boot. --- tasks/swap.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tasks/swap.yml b/tasks/swap.yml index 8dccfb6..ff80d44 100644 --- a/tasks/swap.yml +++ b/tasks/swap.yml @@ -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' when: - proxmox_disable_swap - ansible_memtotal_mb >= proxmox_min_ram_mb_for_no_swap