feat ✨: Add task to gather active swaps and comment swap entries in fstab
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.
This commit is contained in:
@@ -6,18 +6,23 @@
|
|||||||
state: present
|
state: present
|
||||||
reload: yes
|
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
|
- name: swap | Disable swap if host has enough RAM
|
||||||
ansible.builtin.command: swapoff -a
|
ansible.builtin.command: swapoff -a
|
||||||
when:
|
when:
|
||||||
- proxmox_disable_swap
|
- proxmox_disable_swap
|
||||||
- ansible_memtotal_mb >= proxmox_min_ram_mb_for_no_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:
|
ansible.builtin.replace:
|
||||||
path: /etc/fstab
|
path: /etc/fstab
|
||||||
regexp: '^\S+\s+\S+\s+swap\s+.*$'
|
regexp: '^(\s*)(?!#)(\S+\s+\S+\s+swap\s+.*)$'
|
||||||
replace: ''
|
replace: '\1# \2'
|
||||||
when:
|
when:
|
||||||
- proxmox_disable_swap
|
- proxmox_disable_swap
|
||||||
- ansible_memtotal_mb >= proxmox_min_ram_mb_for_no_swap
|
- ansible_memtotal_mb >= proxmox_min_ram_mb_for_no_swap
|
||||||
|
|||||||
Reference in New Issue
Block a user