diff --git a/tasks/configure_swap.yml b/tasks/configure_swap.yml
index 3a6d08872023c1e673e4b38a7fc52f69a9924b31..6e7d7db04f9ab0f901e087c3413bc95bfe589be8 100644
--- a/tasks/configure_swap.yml
+++ b/tasks/configure_swap.yml
@@ -9,7 +9,7 @@
   ansible.builtin.command: swapoff -va
   when:
     - ansible_hostname is not search("validate")
-    - swap_active.stdout == ""
+    - swap_active.stdout | length == 0
   register: disable_swap
   changed_when: disable_swap.stdout not in "swapoff LABEL=swap"
 
@@ -20,4 +20,4 @@
     state: "absent"
   when:
     - ansible_hostname is not search("validate")
-    - swap_active.stdout == ""
+    - swap_active.stdout | length == 0