Skip to content

Instantly share code, notes, and snippets.

@ryanwalder
Created March 20, 2018 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanwalder/90c5de0b59be0ea9b3f542202eabc765 to your computer and use it in GitHub Desktop.
Save ryanwalder/90c5de0b59be0ea9b3f542202eabc765 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Bootstrap salt
if ! mkdir -p /etc/salt/pki/minion; then
echo "Failed to create PKI dir"
exit 1
elif ! echo "master: ${master_ip}" > /etc/salt/minion; then
echo "Failed to set master address"
exit 1
elif ! echo "mine_interval: 1" >> /etc/salt/minion; then
echo "Failed to set min interval"
exit 1
elif ! curl -sSk http://${master_ip}:8000/run \
-d username="${salt_api_user}" \
-d password="${salt_api_pass}" \
-d eauth=pam -d client="wheel" \
-d fun="key.delete" \
-d match="$(hostname -f)"; then
echo "Failed to delete old minion key"
exit 1
elif ! curl -sSk -X POST http://${master_ip}:8000/keys \
-H "Accept: application/x-yaml" \
-d username="${salt_api_user}" \
-d password="${salt_api_pass}" \
-d eauth=pam \
-d mid=$(hostname -f) \
| tar --warning=no-timestamp -C /etc/salt/pki/minion -xf -; then
echo "Failed to setup salt minion keys"
exit 1
elif ! systemctl start salt-minion; then
echo "Unable to start salt-minion service"
exit 1
elif ! salt-call mine.update --retcode-passthrough; then
echo "Unable to refresh salt mine"
exit 1
elif ! salt-call state.apply --retcode-passthrough; then
echo "Unable to run highstate"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment