Files
Balamurali M 038e2f6bb4 feat(server): Allow removing swap
We can now reset swap to desired number. Increase swap functionality is
kept, just in case for now.

Can be a reaction to swap full when it is 8 GB or above to avoid
suffering
2025-03-28 15:46:00 +05:30

42 lines
829 B
YAML

---
- name: Set swap file name
set_fact:
swap_file: "{{ swap_file | default('swap') }}"
- name: Confirm file doesn't exist
stat:
path: '/{{ swap_file }}'
register: stat_result
failed_when: 'stat_result.stat.exists'
when: swap_size | int > 0
- name: Create Swap file
command: fallocate -l {{ swap_size }}G /{{ swap_file }}
when: swap_size | int > 0
- name: Change Swap file permissions
file:
path: '/{{ swap_file }}'
owner: root
group: root
mode: 0600
when: swap_size | int > 0
- name: Make Swap
command: mkswap /{{ swap_file }}
when: swap_size | int > 0
- name: Add Swap to fstab
mount:
name: none
src: '/{{ swap_file }}'
fstype: swap
opts: sw
passno: 0
dump: 0
state: present
when: swap_size | int > 0
- name: Enable Swap
command: swapon -av