From 3e6e277a1ae2d9ab906d884da4a3d942729f9386 Mon Sep 17 00:00:00 2001 From: Jordi Massaguer Pla Date: Wed, 14 Jun 2023 13:23:03 +0200 Subject: [PATCH] Only remove only salt-client if this is a server Otherwise, remove all salt packages. This reverts commit 59104d3fa4f80ddcdda2182580f214b89367debe and adds a "is server" case. s Signed-off-by: Jordi Massaguer Pla --- salt/post_provisioning_cleanup.sh | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/salt/post_provisioning_cleanup.sh b/salt/post_provisioning_cleanup.sh index 9576df97d..40bc43b28 100755 --- a/salt/post_provisioning_cleanup.sh +++ b/salt/post_provisioning_cleanup.sh @@ -14,6 +14,17 @@ fi # Nothing to do in case "install_salt_bundle" grain is not true INSTALL_SALT_BUNDLE=$(${SALT_CALL} --local --log-level=quiet --output=txt grains.get install_salt_bundle) +SERVER=false +ROLES=$(${SALT_CALL} --local --log-level=quiet --output=txt grains.get roles) +if [[ "${ROLES}" == "local: ['server']" ]];then + echo "This is a server" + SERVER=true + PKGS="Salt minion" +else + echo "This is not a server" + PKGS="Salt" +fi + if [[ "$INSTALL_SALT_BUNDLE" != "local: True" ]]; then exit 0 @@ -31,13 +42,25 @@ elif [ -x /usr/bin/apt ]; then INSTALLER=apt fi -echo "Removing Salt packages, except Salt Bundle (venv-salt-minion) ..." +echo "Removing ${PKGS} packages, except Salt Bundle (venv-salt-minion) ..." if [[ "$INSTALLER" == "zypper" ]]; then -zypper -q --non-interactive remove salt-minion > /dev/null 2>&1 ||: + if [[ "$SERVER" == "true" ]];then + zypper -q --non-interactive remove salt-minion > /dev/null 2>&1 ||: + else + zypper -q --non-interactive remove salt salt-minion python3-salt python2-salt > /dev/null 2>&1 ||: + fi elif [[ "$INSTALLER" == "yum" ]]; then -yum -y remove salt salt-minion python3-salt python2-salt > /dev/null 2>&1 ||: + if [[ "$SERVER" == "true" ]];then + yum -y remove salt-minion > /dev/null 2>&1 ||: + else + yum -y remove salt salt-minion python3-salt python2-salt > /dev/null 2>&1 ||: + fi elif [[ "$INSTALLER" == "apt" ]]; then -apt-get --yes purge salt-common > /dev/null 2>&1 ||: + if [[ "$SERVER" == "true" ]];then + apt-get --yes purge salt-client > /dev/null 2>&1 ||: + else + apt-get --yes purge salt-common > /dev/null 2>&1 ||: + fi fi echo "Done!"