diff --git a/tasks/main.yml b/tasks/main.yml index 85b6afe..99957d8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,9 +1,16 @@ --- - when: not (swap_enabled | bool) or swap_size | int > (ansible_swaptotal_mb | int) + 1 block: - - name: Disable active swap + - name: Disable swap ansible.builtin.shell: "test -f {{ swap_path }} && swapoff {{ swap_path }} || true" + - name: Unmount swap file + ansible.posix.mount: + src: "{{ swap_path }}" + path: none + fstype: swap + state: absent + - name: Remove swap file ansible.builtin.file: path: "{{ swap_path }}" @@ -35,6 +42,6 @@ fstype: swap state: present - - name: Enable swap file + - name: Enable swap ansible.builtin.command: "swapon -a" changed_when: False