From 351832ba1d9ee18a029e6c0b01c6538a77dc7b9d Mon Sep 17 00:00:00 2001 From: tu1h Date: Mon, 29 Jul 2024 11:53:49 +0800 Subject: [PATCH] Check CentOS-Base.repo exists for CentOS 7 Signed-off-by: tu1h --- roles/bootstrap-os/tasks/centos.yml | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/roles/bootstrap-os/tasks/centos.yml b/roles/bootstrap-os/tasks/centos.yml index 11559a872..fc9a3cf0c 100644 --- a/roles/bootstrap-os/tasks/centos.yml +++ b/roles/bootstrap-os/tasks/centos.yml @@ -88,24 +88,31 @@ - (ansible_distribution_version | float) < 9 # CentOS 7 EOL at July 1, 2024. -- name: Disable CentOS 7 mirrorlist in CentOS-Base.repo - replace: +- name: Check CentOS-Base.repo exists for CentOS 7 + stat: path: /etc/yum.repos.d/CentOS-Base.repo - regexp: '^mirrorlist=' - replace: '#mirrorlist=' - become: true + register: centos_base_repo_stat when: - ansible_distribution_major_version == "7" # CentOS 7 EOL at July 1, 2024. -- name: Update CentOS 7 baseurl in CentOS-Base.repo - replace: - path: /etc/yum.repos.d/CentOS-Base.repo - regexp: '^#baseurl=http:\/\/mirror.centos.org' - replace: 'baseurl=http:\/\/vault.centos.org' - become: true +- name: Update CentOS 7 CentOS-Base.repo when: - ansible_distribution_major_version == "7" + - centos_base_repo_stat.stat.exists + become: true + block: + - name: Disable CentOS 7 mirrorlist in CentOS-Base.repo + replace: + path: "{{ centos_base_repo_stat.stat.path }}" + regexp: '^mirrorlist=' + replace: '#mirrorlist=' + + - name: Update CentOS 7 baseurl in CentOS-Base.repo + replace: + path: "{{ centos_base_repo_stat.stat.path }}" + regexp: '^#baseurl=http:\/\/mirror.centos.org' + replace: 'baseurl=http:\/\/vault.centos.org' # CentOS ships with python installed