diff --git a/ansible/roles/prechecks/tasks/package_checks.yml b/ansible/roles/prechecks/tasks/package_checks.yml
index ccaa52932847f795537ec48072ebcea8d2b556ab..20def920f3fabefe7273681c345ea0733a258ed9 100644
--- a/ansible/roles/prechecks/tasks/package_checks.yml
+++ b/ansible/roles/prechecks/tasks/package_checks.yml
@@ -20,11 +20,13 @@
 # to check. as ansible_version does not provide major.minor in dict, we need to
 # set it as variable.
 - name: Checking Ansible version
-  vars:
-    ansible_version_host: "{{ ansible_version.major }}.{{ ansible_version.minor }}"
-  fail:
-    msg: >-
+  assert:
+    that:
+      - ansible_version_host is version(ansible_version_min, '>=')
+      - ansible_version_host is version(ansible_version_max, '<=')
+    fail_msg: >-
       Ansible version should be between {{ ansible_version_min }} and {{ ansible_version_max }}.
       Current version is {{ ansible_version.full }} which is not supported.
+  vars:
+    ansible_version_host: "{{ ansible_version.major }}.{{ ansible_version.minor }}"
   run_once: true
-  when: ansible_version_host is version(ansible_version_min, '<') or ansible_version_host is version(ansible_version_max, '>')