Updated the task to use `ansible.builtin.command` instead of the deprecated `command` module for better compatibility with newer Ansible versions.
29 lines
777 B
YAML
29 lines
777 B
YAML
---
|
|
- name: swap | Set vm.swappiness
|
|
ansible.posix.sysctl:
|
|
name: vm.swappiness
|
|
value: "{{ proxmox_swapiness }}"
|
|
state: present
|
|
reload: yes
|
|
|
|
- name: swap | Gather active swaps
|
|
ansible.builtin.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
|
|
- active_swaps.stdout != ""
|
|
|
|
- name: swap | Comment swap entries in fstab
|
|
ansible.builtin.replace:
|
|
path: /etc/fstab
|
|
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
|