git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/onboarding/puppet.conf.sh
diff options
context:
space:
mode:
Diffstat (limited to 'onboarding/puppet.conf.sh')
-rwxr-xr-xonboarding/puppet.conf.sh63
1 files changed, 63 insertions, 0 deletions
diff --git a/onboarding/puppet.conf.sh b/onboarding/puppet.conf.sh
new file mode 100755
index 0000000..ee05858
--- /dev/null
+++ b/onboarding/puppet.conf.sh
@@ -0,0 +1,63 @@
+#!/usr/bin/env bash
+
+function myhelp {
+ printf '\n'
+ printf '\033[1mUSAGE:\033[0m %b [ -r REMOTEHOST ]\n' "$(basename "$0")"
+ printf '\n'
+ (
+ printf -- '--help,\n'
+ printf -- '-h;This help\n'
+ printf -- '--remote,\n'
+ printf -- '-r;Execute on remote host instead of localhost.\n'
+ printf ';Specify REMOTEHOST for rsync+ssh execution (as you would with rsync and ssh).\n'
+ ) | column -ts\;
+ printf '\n'
+}
+
+declare EREMOTE=0 RHOST
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ '--help'|'-h')
+ myhelp
+ exit 0
+ ;;
+ '--remote'|'-r')
+ EREMOTE=1
+ shift
+ RHOST="$1"
+ shift
+
+ ;;
+ *)
+ myhelp
+ printf '\033[3m\033[1mWrong parameter:\033[0m "%b"\n' "$1" >&2
+ exit 101
+ ;;
+ esac
+done
+MYDIR="$(cd "$(dirname "$0")" && pwd)" || exit 101
+if [ "$EREMOTE" -gt 0 ]; then
+ rsync -auP "${MYDIR}/puppet.conf.epp" "${MYDIR}/puppet.conf.pp" "${RHOST}:/tmp/" || exit 110
+ ARHOST="$(printf '%b' "$RHOST" | awk -F'@' '{print $NF}')"
+ printf '\033[3mExecuting "puppet apply" for initial onboarding configuration:\033[0m\n'
+ ssh "$RHOST" '/usr/bin/sudo puppet apply -t /tmp/puppet.conf.pp'
+ case "$?" in
+ 0|2)
+ printf '\033[3mRunning "puppet agent" once to onboard system:\033[0m\n'
+ ssh "$RHOST" '/usr/bin/sudo puppet agent -t'
+ case "$?" in
+ 0|2) /usr/bin/true ;;
+ *) exit 112 ;;
+ esac
+ ;;
+ *)
+ printf '\n\n\033[3m\033[33;1mRun the following commands on %b:\033[0m\n' "$ARHOST"
+ printf ' • /usr/bin/sudo puppet apply -t /tmp/puppet.conf.pp\n'
+ printf ' • /usr/bin/sudo puppet agent -t\n\n'
+ ssh "$RHOST" || exit 111
+ ;;
+ esac
+else
+ cp -vp "${MYDIR}/puppet.conf.epp" "/tmp/" || exit 102
+ /usr/bin/sudo puppet apply -t "${MYDIR}/puppet.conf.pp" || exit 103
+fi