From 50d44205a929a911cf13029d910e8d3b54bd4b0c Mon Sep 17 00:00:00 2001
From: Erik Berg <openstack@slipsprogrammor.no>
Date: Mon, 9 Jan 2023 18:30:23 +0100
Subject: [PATCH] host_os: Use assert on checks for readability

assert will also fail when we're not meeting the conditions, makes
clear what we're actually testing, and isn't listed as a skipped task
when the condition is ok.

Change-Id: I7d316e11a733c63133cc80677ec1e790e76bf8c6
---
 .../roles/prechecks/tasks/host_os_checks.yml   | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/ansible/roles/prechecks/tasks/host_os_checks.yml b/ansible/roles/prechecks/tasks/host_os_checks.yml
index 12dc80e5dc..33e3ad6d99 100644
--- a/ansible/roles/prechecks/tasks/host_os_checks.yml
+++ b/ansible/roles/prechecks/tasks/host_os_checks.yml
@@ -1,22 +1,22 @@
 ---
 - name: Checking host OS distribution
-  fail:
-    msg: >-
+  assert:
+    that: ansible_facts.distribution in host_os_distributions
+    fail_msg: >-
       Host OS distribution {{ ansible_facts.distribution }} is not supported.
       Supported distributions are: {{ host_os_distributions.keys() | join(', ') }}
-  when: ansible_facts.distribution not in host_os_distributions
 
 - name: Checking host OS release or version
-  fail:
-    msg: >-
+  assert:
+    that:
+      - ansible_facts.distribution_release in host_os_distributions[ansible_facts.distribution] or
+        ansible_facts.distribution_version in host_os_distributions[ansible_facts.distribution] or
+        ansible_facts.distribution_major_version in host_os_distributions[ansible_facts.distribution]
+    fail_msg: >-
       {{ ansible_facts.distribution }} release {{ ansible_facts.distribution_release }}
       version {{ ansible_facts.distribution_version }} is not supported.
       Supported releases are:
       {{ host_os_distributions[ansible_facts.distribution] | join(', ') }}
-  when:
-    - ansible_facts.distribution_release not in host_os_distributions[ansible_facts.distribution]
-    - ansible_facts.distribution_version not in host_os_distributions[ansible_facts.distribution]
-    - ansible_facts.distribution_major_version not in host_os_distributions[ansible_facts.distribution]
 
 - name: Checking if CentOS is Stream
   become: true