Fix: Add CentOS 9 support and cleanup prepare.yml 81/73981/3
authorAnil Belur <abelur@linuxfoundation.org>
Fri, 12 Dec 2025 13:07:23 +0000 (23:07 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Fri, 12 Dec 2025 23:03:19 +0000 (09:03 +1000)
- Add CentOS-9.yaml vars file for CentOS Stream 9 support
- Simplify prepare.yml by removing duplicate package installations
- Update package installation logic in tasks/main.yml
- Use ansible_facts instead of deprecated variables

This enables the role to work with CentOS Stream 9 and follows
the same patterns used in other updated roles.

Change-Id: Ib871a115a4b2cad7635b0fcb3b05d6ad3300bcfb
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
molecule/default/prepare.yml
tasks/main.yml
vars/CentOS-9.yaml [moved from vars/CentOS Stream-9.yaml with 96% similarity]

index 4adadfe..677c230 100644 (file)
@@ -6,50 +6,28 @@
   tasks:
     - name: Update APT cache
       ansible.builtin.package:
-        update_cache: yes
-      when: ansible_distribution == 'Ubuntu'
+        update_cache: true
+      when: ansible_facts['distribution'] == 'Ubuntu'
       become: true
 
-    - name: Install GPG certs
-      ansible.builtin.rpm_key:
+    - name: Install EPEL for CentOS/RHEL 9+
+      ansible.builtin.dnf:
+        name: epel-release
         state: present
-        key: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-8
-      when: ansible_os_family == 'RedHat'
+      when: ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('9', '>=')
       become: true
 
-    - name: Install EPEL repository
+    - name: Install EPEL for CentOS/RHEL 8
       ansible.builtin.yum:
-        name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm
+        name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_facts['distribution_major_version'] }}.noarch.rpm
         state: present
-      when: ansible_os_family == 'RedHat'
+        disable_gpg_check: true
+      when: ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '8'
       become: true
 
-    - name: Install yum-plugin-versionlock
-      ansible.builtin.yum:
-        name:
-          - yum-plugin-versionlock
-      when: ansible_os_family == 'RedHat'
-      become: true
-
-    - name: Install mock
-      ansible.builtin.yum:
-        name:
-          - mock-2.17-1.el7
-        state: present
-      when:
-        - ansible_os_family == 'RedHat' and ansible_distribution_major_version == "7"
-      become: true
-
-    - name: Lock mock-core-configs version$
-      ansible.builtin.command: yum versionlock mock
-      when:
-        - ansible_os_family == 'RedHat' and ansible_distribution_major_version == "7"
-      become: true
-
-    - name: Install mock-core-configs from remote repo
-      ansible.builtin.yum:
-        name: https://rpmfind.net/linux/epel/testing/7/aarch64/Packages/m/mock-core-configs-31.6-1.el7.noarch.rpm
-        state: present
-      when:
-        - ansible_os_family == 'RedHat' and ansible_distribution_major_version == "7"
+    - name: Replace curl-minimal with curl on CentOS 9+
+      ansible.builtin.shell: |
+        dnf remove -y curl-minimal && dnf install -y curl
+      when: ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('9', '>=')
       become: true
+      changed_when: true
index 7ae0f1f..1630552 100644 (file)
@@ -2,23 +2,26 @@
 - name: Load operating-system specific variables
   ansible.builtin.include_vars: "{{ item }}"
   with_first_found:
-    - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml"
-    - "{{ ansible_distribution }}.yaml"
-    - "{{ ansible_os_family }}.yaml"
+    - files:
+        - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yaml"
+        - "{{ ansible_facts['distribution'] }}.yaml"
+        - "{{ ansible_facts['os_family'] }}.yaml"
+      paths:
+        - "vars"
 
 # Required for direct install of parallel package from linuxsoft.cern.ch
 - name: Install RPM GPG certs
   ansible.builtin.rpm_key:
     state: present
     key: https://linuxsoft.cern.ch/cern/centos/7/os/x86_64/RPM-GPG-KEY-cern
-  when: ansible_os_family == 'RedHat'
+  when: ansible_facts['os_family'] == 'RedHat'
   become: true
 
 - name: Install LF Recommended Tools on RedHat
   ansible.builtin.yum:
     name: "{{ lf_recommended_tools_packages }}"
     state: present
-  when: ansible_os_family == 'RedHat'
+  when: ansible_facts['os_family'] == 'RedHat'
   become: true
 
 - name: Install pre-packages on Debian
@@ -30,7 +33,7 @@
     state: present
   when:
     - ansible_facts['distribution'] == 'Ubuntu'
-    - ansible_distribution_major_version | int >= 24
+    - ansible_facts['distribution_major_version'] | int >= 24
   become: true
 
 - name: Install LF Recommended Tools on Debian
@@ -38,7 +41,7 @@
   ansible.builtin.package:
     name: "{{ lf_recommended_tools_packages }}"
     state: fixed
-  when: ansible_os_family == 'Debian'
+  when: ansible_facts['os_family'] == 'Debian'
   become: true
 
 - name: Install fedora-packager
@@ -46,7 +49,7 @@
     name:
       - fedora-packager
     state: present
-  when: ansible_os_family == 'RedHat'
+  when: ansible_facts['os_family'] == 'RedHat'
   become: true
 
 - name: Install PlantUML
           ansible.builtin.yum:
             name:
               "https://rpm.nodesource.com/{{ nodejs_rhel_rpm_dir }}/el/\
-              {{ ansible_distribution_major_version }}/\
-              {{ ansible_architecture }}/nodesource-release-el\
-              {{ ansible_distribution_major_version }}-1.noarch.rpm"
+              {{ ansible_facts['distribution_major_version'] }}/\
+              {{ ansible_facts['architecture'] }}/nodesource-release-el\
+              {{ ansible_facts['distribution_major_version'] }}-1.noarch.rpm"
             state: present
           when:
-            - ansible_distribution_major_version | int >= 7
-            - ansible_distribution_major_version | int <= 8
+            - ansible_facts['distribution_major_version'] | int >= 7
+            - ansible_facts['distribution_major_version'] | int <= 8
           register: node_repo
 
         - name: Update package cache if repo was added.
           ansible.builtin.command: yum module disable -y nodejs  # noqa command-instead-of-module
           register: module_disable
           changed_when: "'Nothing to do.' not in module_disable.stdout"
-          when: ansible_distribution_major_version | int >= 8
+          when: ansible_facts['distribution_major_version'] | int >= 8
 
         - name: Ensure Node.js and npm are installed.
           ansible.builtin.yum:
similarity index 96%
rename from vars/CentOS Stream-9.yaml
rename to vars/CentOS-9.yaml
index c1dc2d9..928307a 100644 (file)
@@ -2,6 +2,7 @@
 # CentOS Stream 9 specific recommended tools (exclude legacy CentOS7 RPM URLs)
 lf_recommended_tools_packages_distro:
   - bzip2
+  - curl
   - fedora-packager
   - findutils
   - parallel