Fix: Config VOR apt-get install schreiben, sauberer Neustart

- /etc/salt/minion.d/master.conf wird VOR Installation geschrieben
  damit Minion nie mit Default "salt" startet
- Config wird nach Install nochmal geschrieben (falls apt ueberschreibt)
- Stop + killall + sleep + start + restart am Ende
- killall salt-minion auch im Cleanup
This commit is contained in:
cynfo3000 2026-02-22 20:42:38 +00:00
parent 59f73c5c2a
commit 83a7e817c3

View File

@ -35,14 +35,15 @@ fi
echo ""
echo "=== Cleanup alte Installation ==="
# Stop services
echo "Stoppe Services..."
systemctl stop salt-minion 2>/dev/null || true
systemctl stop salt-master 2>/dev/null || true
systemctl disable salt-minion 2>/dev/null || true
systemctl disable salt-master 2>/dev/null || true
# Alle salt-Prozesse killen
killall -9 salt-minion 2>/dev/null || true
killall -9 salt-master 2>/dev/null || true
# Purge ALL salt packages
if [ "$OS" = "debian" ]; then
SALT_PKGS=$(dpkg -l | grep -i salt | awk '{print $2}' || true)
if [ -n "$SALT_PKGS" ]; then
@ -60,7 +61,6 @@ if [ "$OS" = "debian" ]; then
fi
fi
# Remove config, keys, cache, logs
echo "Loesche Verzeichnisse..."
rm -rf /etc/salt
rm -rf /var/cache/salt
@ -70,7 +70,6 @@ rm -rf /srv/salt
rm -rf /srv/pillar
rm -rf /opt/saltstack
# Remove old repo config and keys
rm -f /etc/apt/sources.list.d/salt*.list
rm -f /etc/apt/keyrings/salt-archive-keyring.gpg
rm -f /usr/share/keyrings/salt-archive-keyring.gpg
@ -98,6 +97,19 @@ if [ "$OS" = "debian" ]; then
echo "apt-get update..."
apt-get update 2>&1 || { echo "FEHLER: apt-get update fehlgeschlagen"; exit 1; }
# Config VOR Installation schreiben, damit Minion direkt mit richtigem Master startet
echo "Schreibe Konfiguration..."
mkdir -p /etc/salt/minion.d
mkdir -p /etc/salt/pki/minion
cat > /etc/salt/minion.d/master.conf << EOF
master: $SALT_MASTER
EOF
cat > /etc/salt/grains << EOF
kunde: $KUNDE
EOF
echo "Installiere salt-minion..."
apt-get install -y salt-minion 2>&1 || { echo "FEHLER: salt-minion Installation fehlgeschlagen"; exit 1; }
fi
@ -109,27 +121,24 @@ if ! command -v salt-minion &>/dev/null; then
fi
echo "salt-minion installiert: $(salt-minion --version)"
# Pruefen ob /etc/salt existiert
if [ ! -d /etc/salt ]; then
echo "WARNUNG: /etc/salt existiert nicht, erstelle manuell..."
mkdir -p /etc/salt/minion.d
mkdir -p /etc/salt/pki/minion
fi
# Configure Master
echo "Konfiguriere Minion..."
# Sicherstellen dass Config korrekt ist
mkdir -p /etc/salt/minion.d
cat > /etc/salt/minion.d/master.conf << EOF
master: $SALT_MASTER
EOF
# Set Grains (Kundennummer)
cat > /etc/salt/grains << EOF
kunde: $KUNDE
EOF
# Restart Minion
# Minion sauber starten
echo "Starte Minion..."
systemctl stop salt-minion 2>/dev/null || true
killall -9 salt-minion 2>/dev/null || true
sleep 2
systemctl enable salt-minion
systemctl start salt-minion
sleep 5
systemctl restart salt-minion
echo ""
@ -138,9 +147,11 @@ echo "Salt Version: $(salt-minion --version)"
echo "Minion ID: $(hostname)"
echo "Grain: kunde: $KUNDE"
echo "Master: $SALT_MASTER"
echo "Minion Status: $(systemctl is-active salt-minion)"
echo ""
echo "Verifikation:"
ls -la /etc/salt/
cat /etc/salt/minion.d/master.conf
cat /etc/salt/grains
echo ""
# Zweiter Restart - stellt sicher dass Verbindung zum Master aufgebaut wirdsleep 3systemctl restart salt-minionsleep 2echo "Minion Status: $(systemctl is-active salt-minion)"echo ""
echo "Naechster Schritt: Salt Master kontaktieren fuer Key-Akzeptanz."