blob: c7dbdcbba9e9914ae88beb3bef0fae5385214bc8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#!/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 -- '--skip-warning,\n'
printf -- '-s;Skip countdown and warning about adjusting puppet.conf.epp first\n'
printf ';Specify REMOTEHOST for rsync+ssh execution (as you would with rsync and ssh).\n'
) | column -ts\;
printf '\n'
}
declare EREMOTE=0 RHOST WSKIP=0
while [[ $# -gt 0 ]]; do
case "$1" in
'--help'|'-h')
myhelp
exit 0
;;
'--remote'|'-r')
EREMOTE=1
shift
RHOST="$1"
shift
;;
'--skip-warning'|'-s')
WSKIP=1
shift
;;
*)
myhelp
printf '\033[3m\033[1mWrong parameter:\033[0m "%b"\n' "$1" >&2
exit 101
;;
esac
done
if [ "$WSKIP" -lt 1 ]; then
printf '\n\033[3m\033[1mHave you adjusted puppet.conf.epp yet? '
# shellcheck disable=SC2016
printf ' ($my_server, $my_certname, $my_dns_alt_names)\033[0m\n'
printf 'Starting\033[s in ...'
for (( i=5;i>0;--i )); do
printf '\033[u\033[K in %b...' "$i"
sleep 1
done
fi
printf '\n\n'
MYDIR="$(cd "$(dirname "$0")" && pwd)" || exit 101
if [ "$EREMOTE" -gt 0 ]; then
printf '\033[3mCopying files:\033[0m\n'
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
printf '\033[3mCopying files:\033[0m\n'
cp -vp "${MYDIR}/puppet.conf.epp" "/tmp/" || exit 102
printf '\033[3mExecuting "puppet apply" for initial onboarding configuration:\033[0m\n'
/usr/bin/sudo puppet apply -t "${MYDIR}/puppet.conf.pp" || exit 103
printf '\033[3mRunning "puppet agent" once to onboard system:\033[0m\n'
/usr/bin/sudo puppet agent -t
fi
|