forked from chrisongthb/puppetserver-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuppetserver-bootstrap.sh
75 lines (64 loc) · 2.72 KB
/
puppetserver-bootstrap.sh
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
#!/bin/bash
# https://github.com/chrisongthb/puppetserver-bootstrap
# puppetserver-bootstrap
# configure a single node puppetserver
set -e
set -u
_say () {
echo
echo '###################################################'
echo -e $1
}
##########
_say 'reading properties file and lsb info...'
source /etc/lsb-release
source $(dirname $0)/puppetserver-bootstrap.properties
##########
_say 'preparing apt repos...'
curl -s ${_apt_key_puppetlabs} | apt-key add -
curl -s ${_apt_key_postgresql} | apt-key add -
apt-add-repository -n "${_apt_source_puppetlabs}"
apt-add-repository -n "${_apt_source_postgresql}"
apt-add-repository -n "${_apt_source_universe}" # provides openjdk-8-jre-headless
apt-get update
##########
_say 'cleaning up old puppet stuff...'
apt-get purge -y puppet-agent puppetserver puppetdb
rm -rfv /etc/puppetlabs /opt/puppetlabs /var/tmp/puppetserver-bootstrap/
##########
_say 'installing puppet-agent and puppetserver...'
apt-get install -y puppet-agent puppetserver
##########
_say 'disabling puppet agent...'
systemctl stop puppet.service
systemctl disable puppet.service
systemctl mask puppet.service
/opt/puppetlabs/bin/puppet agent --disable 'puppet should not configure puppetserver'
##########
_say 'configuring puppetserver and installing puppetdb...'
/opt/puppetlabs/bin/puppet config set --section main server $(hostname -f)
/opt/puppetlabs/bin/puppetserver ca setup
apt-get install -y puppetdb
##########
_say 'preparing puppet apply (downloading puppet modules)...'
mkdir -v /var/tmp/puppetserver-bootstrap/
/opt/puppetlabs/bin/puppet module install --target-dir /var/tmp/puppetserver-bootstrap/ puppet-puppetserver
/opt/puppetlabs/bin/puppet module install --target-dir /var/tmp/puppetserver-bootstrap/ puppetlabs-puppetdb
/opt/puppetlabs/bin/puppet module install --target-dir /var/tmp/puppetserver-bootstrap/ puppetlabs-lvm
/opt/puppetlabs/bin/puppet module install --target-dir /var/tmp/puppetserver-bootstrap/ puppet-r10k
/opt/puppetlabs/bin/puppet module install --target-dir /var/tmp/puppetserver-bootstrap/ puppet-hiera
##########
_say 'starting puppet apply...'
set +e
/opt/puppetlabs/bin/puppet apply --detailed-exitcodes --modulepath=/var/tmp/puppetserver-bootstrap/ $(dirname $0)/puppetserver-bootstrap.pp
_rc=$?
if [ $_rc -ge 4 -o $_rc -eq 1 ]; then
_say "something went wrong!\ndebug the error above and retry the puppet apply via:\n\n /opt/puppetlabs/bin/puppet apply --modulepath=/var/tmp/puppetserver-bootstrap/ $(dirname $0)/puppetserver-bootstrap.pp\n"
read -p 'OK? [press enter]'
else
_say 'installation and configuration finished!'
fi
set -e
##########
_say 'printing systemd status of all puppet components...'
systemctl --no-pager status puppet.service puppetserver.service puppetdb.service webhook || true