diff --git a/tasks/main.yml b/tasks/main.yml index ec39a92..85b6afe 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,5 @@ --- -- when: swap_size | int > (ansible_swaptotal_mb | int) + 1 or not (swap_enabled | bool) +- when: not (swap_enabled | bool) or swap_size | int > (ansible_swaptotal_mb | int) + 1 block: - name: Disable active swap ansible.builtin.shell: "test -f {{ swap_path }} && swapoff {{ swap_path }} || true" @@ -9,7 +9,9 @@ path: "{{ swap_path }}" state: absent -- when: swap_size | int > (ansible_swaptotal_mb | int) + 1 +- when: + - swap_enabled | bool + - swap_size | int > (ansible_swaptotal_mb | int) + 1 block: - name: Create swap file ansible.builtin.command: "fallocate -l {{ swap_size }}M {{ swap_path }}"