Last active
February 5, 2019 13:48
-
-
Save WillSams/23644fbba00c7a7d9a637a32651364df to your computer and use it in GitHub Desktop.
Install and Configure Salt Master on Debian-based System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o nounset # unset variables are errors | |
SCRIPTVERSION="2019.01.25-Debian" | |
SCRIPTNAME="install-salt-master.sh" | |
SCRIPTFULLNAME="$0" | |
BROADCAST='192.168.56.1/24' #local network broadcast IP & subnet | |
echoerror() { printf "\033[1;31m * ERROR\033[0m: %s\\n" "$@" 1>&2; } | |
usage() { | |
cat << EOT | |
Usage : ${SCRIPTNAME} [options] | |
Options: | |
-h Display this message | |
-v Display script version | |
-b Network's broadcast IP address & subnet. 192.168.56.1/24. | |
EOT | |
} # ---------- end of function usage ---------- | |
while getopts ':hvb:' opt | |
do | |
case "${opt}" in | |
h ) usage; exit 0 ;; | |
v ) echo "$0 -- Version $SCRIPTVERSION"; exit 0 ;; | |
b ) BROADCAST=$OPTARG ;; | |
\?) echo | |
echoerror "Option does not exist : $OPTARG" | |
usage | |
exit 1 | |
;; | |
esac # --- end of case --- | |
done | |
shift $((OPTIND-1)) | |
if [ -f /etc/salt/master ]; then | |
echo "Salt (master) is already installed on $HOSTNAME." | |
else | |
echo "************************ SALT-MASTER INSTALL **************************" | |
echo "Installing SALT-MASTER" | |
echo "You may be prompted for root credentials to complete the install." | |
echo "******************************************************************" | |
sudo bash -c "add-apt-repository universe && apt update && apt upgrade -y" | |
sudo bash -c "apt install salt-master salt-cloud salt-doc -y" | |
# create the configuration management directory structure where | |
# the Salt master will look for various files | |
sudo bash -c "mkdir -p /srv/{salt,pillar}" | |
# Set the file_roots dictionary. This basically specifies the locations | |
# where the Salt master will look for configuration management instructions. | |
sudo bash -c "rm /etc/salt/master" | |
sudo bash -c "echo 'file_roots: | |
base: | |
- /srv/salt | |
- /srv/formulas | |
pillar_roots: | |
base: | |
- /srv/pillar' >> /etc/salt/master" | |
sudo bash -c "ufw allow from $BROADCAST to any port 4505" | |
sudo bash -c "ufw allow from $BROADCAST to any port 4506" | |
sudo bash -c "systemctl enable salt-master.service && service salt-master restart" | |
sudo bash -c "salt-key -A -y" #accept all minions (i.e., if you have minions already running) | |
echo "$SCRIPTFULLNAME ($SCRIPTVERSION) complete." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment