fix: Update tasks to use ansible_facts dictionary 95/73995/1
authorAnil Belur <abelur@linuxfoundation.org>
Mon, 15 Dec 2025 12:14:20 +0000 (22:14 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Mon, 15 Dec 2025 12:22:05 +0000 (22:22 +1000)
- Replace ansible_os_family with ansible_facts['os_family']
- Replace ansible_architecture with ansible_facts['architecture']
- Replace ansible_distribution_* with ansible_facts['distribution_*']
- Fix version comparisons to use is version() test
- Update CentOS 9 condition to use >= instead of exact match

Change-Id: I71524fd294652e4b7993e41d1751957d15d4b0f5
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
.github/workflows/gerrit-verify.yaml
molecule/default/molecule.yml
tasks/Debian.yml
tasks/RedHat.yml
tasks/main.yml

index 2eae8b1..2253324 100644 (file)
@@ -111,6 +111,7 @@ jobs:
     strategy:
       matrix:
         distro:
+          - centos9
           - ubuntu2204
           - ubuntu2404
       fail-fast: false
index 007e8f2..008423c 100644 (file)
@@ -4,6 +4,9 @@ dependency:
 driver:
   name: podman
 platforms:
+  - name: centos9
+    image: quay.io/centos/centos:stream9
+    pre_build_image: false
   - name: ubuntu2204
     image: ubuntu:22.04
     pre_build_image: false
@@ -12,13 +15,29 @@ platforms:
     pre_build_image: false
 provisioner:
   name: ansible
-  env:
-    ANSIBLE_CONFIG: ${MOLECULE_PROJECT_DIRECTORY}/ansible.cfg
+  config_options:
+    defaults:
+      callbacks_enabled: profile_tasks
+      inject_facts_as_vars: false
   inventory:
     host_vars:
+      centos9:
+        ansible_python_interpreter: /usr/bin/python3
       ubuntu2204:
         ansible_python_interpreter: /usr/bin/python3
       ubuntu2404:
         ansible_python_interpreter: /usr/bin/python3
+scenario:
+  name: default
+  test_sequence:
+    - destroy
+    - dependency
+    - syntax
+    - create
+    - prepare
+    - converge
+    - side_effect
+    - verify
+    - destroy
 verifier:
   name: ansible
index e318408..f9a6fd7 100644 (file)
@@ -15,6 +15,7 @@
   until: task_result is success
   retries: 3
   delay: 10
+  when: ansible_facts['distribution_version'] is version('24.04', '<')
 
 - name: Install OpenJDK 1.8.0, 11 and 12
   ansible.builtin.package:
@@ -26,7 +27,7 @@
     update_cache: 'yes'
   become: true
   when:
-    - ansible_os_family == 'Debian' and ansible_facts['distribution_major_version'] is version('20.04', '<=')
+    - ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '<=')
 
 - name: Install OpenJDK 17
   ansible.builtin.package:
@@ -36,8 +37,8 @@
     update_cache: 'yes'
   become: true
   when:
-    - ansible_os_family == "Debian"
-    - ansible_distribution_major_version == "11" or ansible_distribution_version >= "18.04"
+    - ansible_facts['os_family'] == "Debian"
+    - ansible_facts['distribution_major_version'] == "11" or ansible_facts['distribution_version'] is version('18.04', '>=')
 
 - name: Install OpenJDK 21
   apt:
     update_cache: 'yes'
   become: true
   when:
-    - ansible_os_family == "Debian"
-    - ansible_distribution_major_version == "13" or ansible_distribution_version >= "20.04"
+    - ansible_facts['os_family'] == "Debian"
+    - ansible_facts['distribution_major_version'] == "13" or ansible_facts['distribution_version'] is version('20.04', '>=')
 
 - name: Set Java path for OpenJDK 11 (non-arm)
   ansible.builtin.set_fact:
     java_path: /usr/lib/jvm/java-1.11.0-openjdk-amd64
   when:
-    - ansible_architecture != "aarch64"
-    - ansible_os_family == 'Debian' and ansible_facts['distribution_major_version'] is version('20.04', '<=')
+    - ansible_facts['architecture'] != "aarch64"
+    - ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '<=')
 
 - name: Set Java path for OpenJDK 11 (arm)
   ansible.builtin.set_fact:
     java_path: /usr/lib/jvm/java-1.11.0-openjdk-arm64
   when:
-    - ansible_architecture == "aarch64"
+    - ansible_facts['architecture'] == "aarch64"
+    - ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '<=')
 
 - name: Set Java path for OpenJDK 21 (non-arm)
   ansible.builtin.set_fact:
     java_path: /usr/lib/jvm/java-1.21.0-openjdk-amd64
   when:
-    - ansible_architecture != "aarch64"
-    - ansible_os_family == 'Debian' and ansible_facts['distribution_major_version'] is version('20.04', '>=')
+    - ansible_facts['architecture'] != "aarch64"
+    - ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '>=')
index dbc1a41..5396eb5 100644 (file)
@@ -4,7 +4,7 @@
     name:
       - epel-release
     state: present
-  when: ansible_os_family == "RedHat"
+  when: ansible_facts['os_family'] == "RedHat"
   become: true
 
 - name: Install OpenJDK 1.8.0, 11
@@ -21,7 +21,7 @@
       - java-17-openjdk-devel
       - java-latest-openjdk-devel
     state: present
-  when: ansible_os_family == "RedHat" and ansible_distribution_major_version == "8"
+  when: ansible_facts['os_family'] == "RedHat" and ansible_facts['distribution_major_version'] == "8"
   become: true
 
 - name: Install OpenJDK 21, latest
@@ -30,7 +30,7 @@
       - java-21-openjdk-devel
       - java-latest-openjdk-devel
     state: present
-  when: ansible_os_family == "RedHat" and ansible_distribution_major_version >= "8"
+  when: ansible_facts['os_family'] == "RedHat" and ansible_facts['distribution_major_version'] is version('9', '>=')
   become: true
 
 - name: Set Java path for OpenJDK 11
index 228a16c..4d4ff18 100644 (file)
@@ -1,10 +1,10 @@
 ---
-- name: Install JDK for {{ ansible_os_family }}
+- name: Install JDK for {{ ansible_facts['os_family'] }}
   ansible.builtin.include_tasks: '{{ item }}'
   with_first_found:
-    - '{{ ansible_os_family }}-{{ ansible_architecture }}.yml'
-    - '{{ ansible_distribution }}.yml'
-    - '{{ ansible_os_family }}.yml'
+    - '{{ ansible_facts["os_family"] }}-{{ ansible_facts["architecture"] }}.yml'
+    - '{{ ansible_facts["distribution"] }}.yml'
+    - '{{ ansible_facts["os_family"] }}.yml'
 
 - name: Set default Java
   become: true