xoxys.swap/tasks/main.yml
Robert Kaussow f874fa89e0
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/notify Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/docs Pipeline was successful
first commit
2024-04-15 16:39:29 +02:00

39 lines
1.0 KiB
YAML

---
- when: swap_size | int > (ansible_swaptotal_mb | int) + 1 or not (swap_enabled | bool)
block:
- name: Disable active swap
ansible.builtin.shell: "test -f {{ swap_path }} && swapoff {{ swap_path }} || true"
- name: Remove swap file
ansible.builtin.file:
path: "{{ swap_path }}"
state: absent
- when: swap_size | int > (ansible_swaptotal_mb | int) + 1
block:
- name: Create swap file
ansible.builtin.command: "fallocate -l {{ swap_size }}M {{ swap_path }}"
- name: Format swap file
ansible.builtin.command: "mkswap {{ swap_path }}"
- when: swap_enabled | bool
block:
- name: Fix file permissions
ansible.builtin.file:
path: "{{ swap_path }}"
owner: root
group: root
mode: "0600"
- name: Mount swap file
ansible.posix.mount:
src: "{{ swap_path }}"
path: swap
fstype: swap
state: present
- name: Enable swap file
ansible.builtin.command: "swapon -a"
changed_when: False