From 2565eccc4cf60d57be60b68498da1e20869c247a Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Thu, 17 Jun 2021 11:23:55 +1000 Subject: [PATCH] Fix: Enable powertools repo for CentOS 8.* vers 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 --- provision/install-base-pkgs-RedHat.yaml | 54 ++++++++++++++++------ ...ix-enable-powertools-repo-e356e1bb23891978.yaml | 10 ++++ 2 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 releasenotes/notes/fix-enable-powertools-repo-e356e1bb23891978.yaml diff --git a/provision/install-base-pkgs-RedHat.yaml b/provision/install-base-pkgs-RedHat.yaml index 1e6ebdf..58eeb1f 100644 --- a/provision/install-base-pkgs-RedHat.yaml +++ b/provision/install-base-pkgs-RedHat.yaml @@ -15,20 +15,48 @@ 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 index 0000000..12ccb60 --- /dev/null +++ b/releasenotes/notes/fix-enable-powertools-repo-e356e1bb23891978.yaml @@ -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 -- 2.16.6