Saltstack docker

From UVOO Tech Wiki
Revision as of 07:14, 31 July 2026 by Busk (talk | contribs) (Created page with "``` #!/bin/bash set -e # ========================================== # CONFIGURATION # ========================================== # Replace with your Dockerized Salt Master's...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#!/bin/bash
set -e

# ==========================================
# CONFIGURATION
# ==========================================
# Replace with your Dockerized Salt Master's IP or DNS name
SALT_MASTER="mysalt.example.com" 

# Uses the machine's hostname by default, or you can hardcode a name (e.g., "web-server-01")
MINION_ID=$(hostname) 
# ==========================================

if [[ $EUID -ne 0 ]]; then
   echo "Error: This script must be run as root. Try using: sudo $0"
   exit 1
fi

echo "==> Installing prerequisites..."
apt-get update
apt-get install -y curl gnupg

echo "==> Adding Salt Project repository for Ubuntu 24.04 LTS (Noble)..."
mkdir -p /etc/apt/keyrings
curl -fsSL -o /etc/apt/keyrings/salt-archive-keyring-2023.gpg \
  https://repo.saltproject.io/salt/py3/ubuntu/24.04/amd64/SALT-PROJECT-GPG-PUBKEY-2023.gpg

echo "deb [signed-by=/etc/apt/keyrings/salt-archive-keyring-2023.gpg arch=amd64] https://repo.saltproject.io/salt/py3/ubuntu/24.04/amd64/3006 noble main" \
  | tee /etc/apt/sources.list.d/salt.list > /dev/null

echo "==> Installing Salt Minion..."
apt-get update
apt-get install -y salt-minion

echo "==> Configuring Minion to connect to $SALT_MASTER..."
mkdir -p /etc/salt/minion.d
echo "master: $SALT_MASTER" > /etc/salt/minion.d/master.conf
echo "$MINION_ID" > /etc/salt/minion_id

echo "==> Enabling and starting Salt Minion service..."
systemctl enable --now salt-minion
systemctl restart salt-minion

echo "=================================================="
echo "Success! The Salt Minion ($MINION_ID) is running."
echo "It has sent its public key to $SALT_MASTER."
echo "You must now log into the Master server and accept this key."
echo "=================================================="
# List pending keys to verify the minion showed up
docker compose exec salt-master salt-key -L

# Accept the specific minion key
docker compose exec salt-master salt-key -a