]> git.apps.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
testnode: Work around rare CentOS infra mirror mismatch 678/head
authorDavid Galloway <dgallowa@redhat.com>
Mon, 16 May 2022 15:41:11 +0000 (11:41 -0400)
committerDavid Galloway <dgallowa@redhat.com>
Mon, 16 May 2022 15:42:17 +0000 (11:42 -0400)
Signed-off-by: David Galloway <dgallowa@redhat.com>
roles/testnode/tasks/yum/baseurls_not_mirrorlists.yml [new file with mode: 0644]
roles/testnode/tasks/yum/repos.yml

diff --git a/roles/testnode/tasks/yum/baseurls_not_mirrorlists.yml b/roles/testnode/tasks/yum/baseurls_not_mirrorlists.yml
new file mode 100644 (file)
index 0000000..5292b56
--- /dev/null
@@ -0,0 +1,30 @@
+---
+- name: dnf check-update to see if mirrorlists are working
+  command: dnf check-update
+  register: mirrorlist_check
+  ignore_errors: true
+
+# Default to false
+- set_fact:
+    use_baseurls: false
+
+- set_fact:
+    use_baseurls: true
+  when: '"all mirrors were already tried" in mirrorlist_check.stderr'
+
+- name: Get list of repo files we need to use baseurls for
+  shell: "grep -l '^mirrorlist' *.repo | grep -v epel | cut -d '.' -f1"
+  args:
+    chdir: /etc/yum.repos.d
+  register: repo_files_with_mirrorlists
+  when: use_baseurls|bool is true
+
+- name: Comment mirrorlist parameter in each repo
+  shell: "sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/{{ item }}.repo"
+  with_items: "{{ repo_files_with_mirrorlists.stdout_lines }}"
+  when: use_baseurls|bool is true
+
+- name: Use a baseurl instead
+  shell: "echo 'baseurl=http://packages.oit.ncsu.edu/centos/{{ ansible_distribution_major_version }}{{ dash_stream }}/{% if item == \"CentOS-Extras\" %}extras{% else %}{{ item | regex_replace('CentOS-','') }}{% endif %}/{{ ansible_architecture }}/os/' >> /etc/yum.repos.d/{{ item }}.repo"
+  with_items: "{{ repo_files_with_mirrorlists.stdout_lines }}"
+  when: use_baseurls|bool is true
index 278d8d7f6ed0261d899bf7a61adc74d3b42429b8..7a99ada414ab98c13ef8bc1f1ff0e2446c326291 100644 (file)
   with_dict: "{{ yum_repos|default({}) | combine(additional_yum_repos|default({}), recursive=True) }}"
   when: (yum_repos.keys() | length > 0) or (additional_yum_repos.keys() | length > 0)
 
+# Occasionally when the yum repo mirrors get updated, we get 404s when using mirrorlist
+# but not when using baseurls. No idea why.
+- include_tasks: yum/baseurls_not_mirrorlists.yml
+  when: ansible_distribution == "CentOS"
+
 - name: Enable copr repos
   command: "dnf -y copr enable {{ item }}"
   with_items: "{{ copr_repos }}"