Fix: Enable powertools repo for CentOS 8.* vers 39/68039/5 v0.9.1
authorAnil Belur <abelur@linuxfoundation.org>
Thu, 17 Jun 2021 01:23:55 +0000 (11:23 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Thu, 24 Jun 2021 00:18:58 +0000 (10:18 +1000)
The CR I43b943ddfc38faca does not work as expected since
ansible_facts does not match/return the minor versions of
the Repoid correctly.

For CentOS 8.2.2004 and earlier versions uses repoid as
'PowerTools' while CentOS 8.3.2011 and later versions uses repoid as
'powertools'. To handle this, check the repo file name under
/etc/yum.repos.d/ and enable the correct repository.

Ref: https://wiki.centos.org/Manuals/ReleaseNotes/CentOS8.2011\
Issue: RELENG-3710
Change-Id: Ib6a8d78664bbb5f20d2889fae3ae3b4238007141
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
provision/install-base-pkgs-RedHat.yaml
releasenotes/notes/fix-enable-powertools-repo-e356e1bb23891978.yaml [new file with mode: 0644]

index 1e6ebdf..58eeb1f 100644 (file)
   when:
     - ansible_facts['distribution_major_version'] is version('8', '<')
 
-- name: Enable Powertools
+# Note: Using ansible_facts does not match/return the minor versions of the
+# Repoid (for CentOS 8.2.2004 and earlier is 'PowerTools' and for CentOS 8.3.2011
+# and later the repo name is 'powertools'. To handle this check the repo file path
+# and enable the correct repo.
+# Ref: https://wiki.centos.org/Manuals/ReleaseNotes/CentOS8.2011#Yum_repo_file_and_repoid_changes
+- name: Enable PowerTools repository for CentOS 8.{0,2,3}
   block:
-    - name: Enable powertools on version >= 8.3
-      command:
-        cmd: dnf config-manager --set-enabled powertools
-        warn: no
-      when: ansible_facts['distribution_version'] is version('8.3', '>=')
-    - name: Enable Powertools on versions < 8.3
-      command:
-        cmd: dnf config-manager --set-enabled PowerTools
-        warn: no
-      when: ansible_facts['distribution_version'] is version('8.3', '<')
-  become: true
-  when: ansible_facts['distribution_major_version'] is version('8', '>=')
+    - name: Check the file name in path '/etc/yum.repos.d/' for CentOS 8.{2.2004} or earlier versions
+      shell: grep -lE "^\[PowerTools\]" /etc/yum.repos.d/*.repo
+      register: repofile
+      changed_when: false
+      failed_when: false
+      check_mode: no
+
+    - name: Enable 'PowerTools' repo for CentOS 8.{2.2004} or earlier versions if the file exist
+      ini_file:
+        path: "{{ repofile.stdout }}"
+        section: "PowerTools"
+        option: enabled
+        value: "1"
+        no_extra_spaces: true
+      when: repofile.rc == 0
+      become: true
+
+    - name: Check the file name in path '/etc/yum.repos.d/' for CentOS 8.{3.2011} or later versions
+      shell: grep -lE "^\[powertools\]" /etc/yum.repos.d/*.repo
+      register: repofile
+      changed_when: false
+      failed_when: false
+      check_mode: no
+
+    - name: Enable 'powertools' repo for CentOS 8.{3.2011} or later versions if the file exist
+      ini_file:
+        path: "{{ repofile.stdout }}"
+        section: "powertools"
+        option: enabled
+        value: 1
+        no_extra_spaces: true
+      when: repofile.rc == 0
+      become: true
+  when:
+    - ansible_facts.distribution_major_version|int >= 8
 
 - name: Install base packages
   yum:
diff --git a/releasenotes/notes/fix-enable-powertools-repo-e356e1bb23891978.yaml b/releasenotes/notes/fix-enable-powertools-repo-e356e1bb23891978.yaml
new file mode 100644 (file)
index 0000000..12ccb60
--- /dev/null
@@ -0,0 +1,10 @@
+---
+fixes:
+  - |
+    Using ansible_facts does not match/return the minor versions of the
+    Repoid. For CentOS 8.2.2004 and earlier versions uses repoid as
+    'PowerTools' while CentOS 8.3.2011 and later versions uses repoid as
+    'powertools'. To handle this, check the repo file name under
+    /etc/yum.repos.d/ and enable the correct repository.
+
+    https://wiki.centos.org/Manuals/ReleaseNotes/CentOS8.2011#Yum_repo_file_and_repoid_changes