From 1eb988cdd1a5fb120fa5cac1d076bcb29711ef24 Mon Sep 17 00:00:00 2001 From: to-bar <46519524+to-bar@users.noreply.github.com> Date: Thu, 10 Oct 2019 12:03:40 +0200 Subject: [PATCH] Fix for hosts without yum-utils package #536 --- .../playbooks/roles/common/tasks/RedHat.yml | 1 + .../files/client/RedHat/add-epirepo-client.sh | 1 - .../client/RedHat/disable-system-repos.sh | 17 ++++++++++---- .../client/RedHat/enable-system-repos.sh | 23 +++++++++++++++---- .../centos-7/requirements.txt | 1 + .../redhat-7/requirements.txt | 1 + 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/common/tasks/RedHat.yml b/core/src/epicli/data/common/ansible/playbooks/roles/common/tasks/RedHat.yml index a20029ef2a..c61939f989 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/common/tasks/RedHat.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/common/tasks/RedHat.yml @@ -24,6 +24,7 @@ - sysstat - python-setuptools - openssl + - yum-utils - yum-versionlock - logrotate - ebtables diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/add-epirepo-client.sh b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/add-epirepo-client.sh index fd6c3c313d..e6c21587e2 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/add-epirepo-client.sh +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/add-epirepo-client.sh @@ -15,6 +15,5 @@ enabled=1 gpgcheck=0 EOF -yum-config-manager --enable epirepo yum makecache fast yum repolist \ No newline at end of file diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/disable-system-repos.sh b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/disable-system-repos.sh index 858c21d8f5..d50a666400 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/disable-system-repos.sh +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/disable-system-repos.sh @@ -1,9 +1,16 @@ #!/bin/bash -eu REPOS_LIST_FILE=/var/tmp/enabled-system-repos.txt +YUM_REPOS_BACKUP_FILE=/etc/yum.repos.d/yum.repos.d-epi-backup.tar -cat $REPOS_LIST_FILE | while read repository -do - echo "Disabling repository: $repository" - yum-config-manager --disable $repository -done \ No newline at end of file +if yum-config-manager --version > /dev/null 2>&1; then + cat $REPOS_LIST_FILE | while read repository + do + echo "Disabling repository: $repository" + yum-config-manager --disable $repository + done +elif [ ! -f $YUM_REPOS_BACKUP_FILE ]; then # for hosts where yum-utils is not available + echo "Disabling all yum repositories by backup & remove files in /etc/yum.repos.d" + tar -cv --verify --directory="/" --file=$YUM_REPOS_BACKUP_FILE /etc/yum.repos.d && + rm -f /etc/yum.repos.d/*.repo +fi \ No newline at end of file diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/enable-system-repos.sh b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/enable-system-repos.sh index 42aeef3d73..9e709094c3 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/enable-system-repos.sh +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/client/RedHat/enable-system-repos.sh @@ -1,9 +1,22 @@ #!/bin/bash -eu REPOS_LIST_FILE=/var/tmp/enabled-system-repos.txt +YUM_REPOS_BACKUP_FILE=/etc/yum.repos.d/yum.repos.d-epi-backup.tar -cat $REPOS_LIST_FILE | while read repository -do - echo "Enabling repository: $repository" - yum-config-manager --enable $repository -done \ No newline at end of file +if [ -f $YUM_REPOS_BACKUP_FILE ]; then # hosts without yum-config-manager + echo "Restoring /etc/yum.repos.d/*.repo from: $YUM_REPOS_BACKUP_FILE" + if tar -xv --file $YUM_CONFIG_BACKUP_FILE_PATH --directory /etc/yum.repos.d \ + --strip-components=2 etc/yum.repos.d/*.repo; then + echo "yum repositories restored" + rm -f $YUM_REPOS_BACKUP_FILE + else + echo "Extracting tar failed: $YUM_REPOS_BACKUP_FILE" + exit 2 + fi +else # hosts with yum-config-manager + cat $REPOS_LIST_FILE | while read repository + do + echo "Enabling repository: $repository" + yum-config-manager --enable $repository + done +fi \ No newline at end of file diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.txt b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.txt index 3b6c6113d7..8f6f8b9a02 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.txt +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/centos-7/requirements.txt @@ -101,6 +101,7 @@ wget xorg-x11-font-utils # for grafana xorg-x11-server-utils # for grafana yum-plugin-versionlock +yum-utils [files] https://github.com/prometheus/haproxy_exporter/releases/download/v0.10.0/haproxy_exporter-0.10.0.linux-amd64.tar.gz diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/requirements.txt b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/requirements.txt index 4912e1dfa3..b928407ae7 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/requirements.txt +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/files/download-requirements/redhat-7/requirements.txt @@ -92,6 +92,7 @@ wget xorg-x11-font-utils # for grafana xorg-x11-server-utils # for grafana yum-plugin-versionlock +yum-utils [files] https://github.com/prometheus/haproxy_exporter/releases/download/v0.10.0/haproxy_exporter-0.10.0.linux-amd64.tar.gz