From e0ff9a0283bd870df72ea7dec62d55ef0b8ed972 Mon Sep 17 00:00:00 2001
From: Bartosz Bezak <bartosz@stackhpc.com>
Date: Wed, 8 Mar 2023 12:57:02 +0100
Subject: [PATCH] Fixes repositories files name in Rocky Linux 9

Distributions moved to lowercase names with RHEL 9 release.
This patch also removes previously created uppercase files.

Story: 2010637
Task: 47604
Change-Id: I8bf75ce44b9ec1fdd477fcddf2deebf2929d9fc1
---
 ansible/roles/dnf/tasks/local-mirror.yml        | 16 ++++++++++++++--
 .../dnf/templates/CentOS-Stream-BaseOS.repo.j2  | 17 -----------------
 .../roles/dnf/templates/Rocky-BaseOS.repo.j2    | 16 ----------------
 ...eam-Extras.repo.j2 => centos-extras.repo.j2} |  0
 ...-Stream-AppStream.repo.j2 => centos.repo.j2} | 10 +++++++++-
 ...ocky-Extras.repo.j2 => rocky-extras.repo.j2} |  2 +-
 .../{Rocky-AppStream.repo.j2 => rocky.repo.j2}  |  9 ++++++++-
 ...uppercase-repo-file-r9-3ed29c34d2c945c7.yaml |  5 +++++
 8 files changed, 37 insertions(+), 38 deletions(-)
 delete mode 100644 ansible/roles/dnf/templates/CentOS-Stream-BaseOS.repo.j2
 delete mode 100644 ansible/roles/dnf/templates/Rocky-BaseOS.repo.j2
 rename ansible/roles/dnf/templates/{CentOS-Stream-Extras.repo.j2 => centos-extras.repo.j2} (100%)
 rename ansible/roles/dnf/templates/{CentOS-Stream-AppStream.repo.j2 => centos.repo.j2} (70%)
 rename ansible/roles/dnf/templates/{Rocky-Extras.repo.j2 => rocky-extras.repo.j2} (96%)
 rename ansible/roles/dnf/templates/{Rocky-AppStream.repo.j2 => rocky.repo.j2} (71%)
 create mode 100644 releasenotes/notes/fix-uppercase-repo-file-r9-3ed29c34d2c945c7.yaml

diff --git a/ansible/roles/dnf/tasks/local-mirror.yml b/ansible/roles/dnf/tasks/local-mirror.yml
index 98241efa..da25a034 100644
--- a/ansible/roles/dnf/tasks/local-mirror.yml
+++ b/ansible/roles/dnf/tasks/local-mirror.yml
@@ -1,7 +1,7 @@
 ---
-- name: Copy CentOS repo templates
+- name: Copy Rocky/CentOS repo templates
   vars:
-    repo_file_prefix: "{{ ansible_facts.distribution }}{% if ansible_facts.distribution == 'CentOS'%}-Stream{% endif %}"
+    repo_file_prefix: "{{ ansible_facts.distribution | lower }}"
   template:
     src: "{{ item }}.j2"
     dest: /etc/yum.repos.d/{{ item }}
@@ -9,6 +9,18 @@
     group: root
     mode: 0664
   become: True
+  loop:
+    - "{{ repo_file_prefix }}.repo"
+    - "{{ repo_file_prefix }}-extras.repo"
+
+# TODO(bbezak): remove following task in B release
+- name: Remove incorrect uppercase repo files
+  vars:
+    repo_file_prefix: "{{ ansible_facts.distribution }}{% if ansible_facts.distribution == 'CentOS'%}-Stream{% endif %}"
+  file:
+    path: /etc/yum.repos.d/{{ item }}
+    state: absent
+  become: True
   loop:
     - "{{ repo_file_prefix }}-AppStream.repo"
     - "{{ repo_file_prefix }}-BaseOS.repo"
diff --git a/ansible/roles/dnf/templates/CentOS-Stream-BaseOS.repo.j2 b/ansible/roles/dnf/templates/CentOS-Stream-BaseOS.repo.j2
deleted file mode 100644
index 1ba0747d..00000000
--- a/ansible/roles/dnf/templates/CentOS-Stream-BaseOS.repo.j2
+++ /dev/null
@@ -1,17 +0,0 @@
-# CentOS-Stream-BaseOS.repo
-#
-# The mirrorlist system uses the connecting IP address of the client and the
-# update status of each mirror to pick current mirrors that are geographically
-# close to the client.  You should use this for CentOS updates unless you are
-# manually picking other mirrors.
-#
-# If the mirrorlist does not work for you, you can try the commented out
-# baseurl line instead.
-
-[baseos]
-name=CentOS Stream $releasever - BaseOS
-baseurl=http://{{ dnf_centos_mirror_host }}/{{ dnf_centos_mirror_directory }}/$stream/BaseOS/$basearch/os/
-gpgcheck=1
-enabled=1
-gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
-fastestmirror=0
diff --git a/ansible/roles/dnf/templates/Rocky-BaseOS.repo.j2 b/ansible/roles/dnf/templates/Rocky-BaseOS.repo.j2
deleted file mode 100644
index 0931719b..00000000
--- a/ansible/roles/dnf/templates/Rocky-BaseOS.repo.j2
+++ /dev/null
@@ -1,16 +0,0 @@
-# Rocky-BaseOS.repo
-#
-# The mirrorlist system uses the connecting IP address of the client and the
-# update status of each mirror to pick current mirrors that are geographically
-# close to the client.  You should use this for Rocky updates unless you are
-# manually picking other mirrors.
-#
-# If the mirrorlist does not work for you, you can try the commented out
-# baseurl line instead.
-
-[baseos]
-name=Rocky Linux $releasever - BaseOS
-baseurl=http://{{ dnf_rocky_mirror_host }}/{{ dnf_rocky_mirror_directory }}/$releasever/BaseOS/$basearch/os/
-gpgcheck=1
-enabled=1
-gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
diff --git a/ansible/roles/dnf/templates/CentOS-Stream-Extras.repo.j2 b/ansible/roles/dnf/templates/centos-extras.repo.j2
similarity index 100%
rename from ansible/roles/dnf/templates/CentOS-Stream-Extras.repo.j2
rename to ansible/roles/dnf/templates/centos-extras.repo.j2
diff --git a/ansible/roles/dnf/templates/CentOS-Stream-AppStream.repo.j2 b/ansible/roles/dnf/templates/centos.repo.j2
similarity index 70%
rename from ansible/roles/dnf/templates/CentOS-Stream-AppStream.repo.j2
rename to ansible/roles/dnf/templates/centos.repo.j2
index 667c6c85..b6fb3f97 100644
--- a/ansible/roles/dnf/templates/CentOS-Stream-AppStream.repo.j2
+++ b/ansible/roles/dnf/templates/centos.repo.j2
@@ -1,4 +1,4 @@
-# CentOS-Stream-AppStream.repo
+# centos.repo
 #
 # The mirrorlist system uses the connecting IP address of the client and the
 # update status of each mirror to pick current mirrors that are geographically
@@ -8,6 +8,14 @@
 # If the mirrorlist does not work for you, you can try the commented out
 # baseurl line instead.
 
+[baseos]
+name=CentOS Stream $releasever - BaseOS
+baseurl=http://{{ dnf_centos_mirror_host }}/{{ dnf_centos_mirror_directory }}/$stream/BaseOS/$basearch/os/
+gpgcheck=1
+enabled=1
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
+fastestmirror=0
+
 [appstream]
 name=CentOS Stream $releasever - AppStream
 baseurl=http://{{ dnf_centos_mirror_host }}/{{ dnf_centos_mirror_directory }}/$stream/AppStream/$basearch/os/
diff --git a/ansible/roles/dnf/templates/Rocky-Extras.repo.j2 b/ansible/roles/dnf/templates/rocky-extras.repo.j2
similarity index 96%
rename from ansible/roles/dnf/templates/Rocky-Extras.repo.j2
rename to ansible/roles/dnf/templates/rocky-extras.repo.j2
index ffb04c8f..7ea0fa6b 100644
--- a/ansible/roles/dnf/templates/Rocky-Extras.repo.j2
+++ b/ansible/roles/dnf/templates/rocky-extras.repo.j2
@@ -1,4 +1,4 @@
-# Rocky-Extras.repo
+# rocky-extras.repo
 #
 # The mirrorlist system uses the connecting IP address of the client and the
 # update status of each mirror to pick current mirrors that are geographically
diff --git a/ansible/roles/dnf/templates/Rocky-AppStream.repo.j2 b/ansible/roles/dnf/templates/rocky.repo.j2
similarity index 71%
rename from ansible/roles/dnf/templates/Rocky-AppStream.repo.j2
rename to ansible/roles/dnf/templates/rocky.repo.j2
index e46b38de..0c4b990c 100644
--- a/ansible/roles/dnf/templates/Rocky-AppStream.repo.j2
+++ b/ansible/roles/dnf/templates/rocky.repo.j2
@@ -1,4 +1,4 @@
-# Rocky-AppStream.repo
+# rocky.repo
 #
 # The mirrorlist system uses the connecting IP address of the client and the
 # update status of each mirror to pick current mirrors that are geographically
@@ -8,6 +8,13 @@
 # If the mirrorlist does not work for you, you can try the commented out
 # baseurl line instead.
 
+[baseos]
+name=Rocky Linux $releasever - BaseOS
+baseurl=http://{{ dnf_rocky_mirror_host }}/{{ dnf_rocky_mirror_directory }}/$releasever/BaseOS/$basearch/os/
+gpgcheck=1
+enabled=1
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
+
 [appstream]
 name=Rocky Linux $releasever - AppStream
 baseurl=http://{{ dnf_rocky_mirror_host }}/{{ dnf_rocky_mirror_directory }}/$releasever/AppStream/$basearch/os/
diff --git a/releasenotes/notes/fix-uppercase-repo-file-r9-3ed29c34d2c945c7.yaml b/releasenotes/notes/fix-uppercase-repo-file-r9-3ed29c34d2c945c7.yaml
new file mode 100644
index 00000000..1d3998b3
--- /dev/null
+++ b/releasenotes/notes/fix-uppercase-repo-file-r9-3ed29c34d2c945c7.yaml
@@ -0,0 +1,5 @@
+---
+fixes:
+  - |
+    Fixes repositories files names in Rocky Linux 9. Distributions moved to
+    lowercase names with RHEL 9 release.
-- 
GitLab