-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuppet_upgrade.sh
69 lines (67 loc) · 2.6 KB
/
puppet_upgrade.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
start_msg() {
cat << EOD | awk '{a=sprintf("%s#",$0);b=sprintf("%-38s",a);gsub(/ $/,"-",b);sub(/#/," ",b);printf "# --- %s - Start of : %s #\n",strftime("%Y-%m-%d %H:%M:%S",systime()),b}'
$*
EOD
}
end_msg() {
cat << EOD | awk '{a=sprintf("%s#",$0);b=sprintf("%-38s",a);gsub(/ $/,"-",b);sub(/#/," ",b);printf "# --- %s - End of : %s #\n",strftime("%Y-%m-%d %H:%M:%S",systime()),b}'
$*
EOD
}
do_upgrade(){
version="$1"
cd /tmp/
echo "### content of pe.conf START ###"
cat /etc/puppetlabs/enterprise/conf.d/pe.conf || (echo "pe.conf not OK";return 1)
echo "### content of pe.conf END ###"
wget https://pm.puppetlabs.com/puppet-enterprise/${version}/puppet-enterprise-${version}-el-7-x86_64.tar.gz || return 1
tar xvf puppet-enterprise-${version}-el-7-x86_64.tar.gz || return 1
cd puppet-enterprise-${version}-el-7-x86_64 || return 1
# run installer with existing config
start_msg ./puppet-enterprise-installer -c /etc/puppetlabs/enterprise/conf.d/pe.conf
if ./puppet-enterprise-installer -c /etc/puppetlabs/enterprise/conf.d/pe.conf
then
end_msg ./puppet-enterprise-installer -c /etc/puppetlabs/enterprise/conf.d/pe.conf SUCCESS
# run puppet agent
puppet agent -t
puppet agent -t
# mail the logfile
if [ ! -x /usr/local/bin/mailit ];then
curl http://huclis02.qvc-intern.de:/inst.images/GIT/admin-scripts/scripts/mailit > /usr/local/bin/mailit
chmod +x /usr/local/bin/mailit
fi
facter -p pe_server_version puppetversion facterversion | /usr/local/bin/mailit -t [email protected] -f /tmp/upgrade_${version}.log -s "Puppet Server Upgrade to ${version} on $(hostname -f)"
# tidyup
cd /tmp
rm -rf puppet-enterprise-${version}-el-7-x86_64*
else
end_msg ./puppet-enterprise-installer -c /etc/puppetlabs/enterprise/conf.d/pe.conf FAIL
echo "Non Zereo return code from installer script. please check logfile.."
fi
}
disable_envs() {
# move envs to other location to speed up puppetserver restart
mkdir -p /etc/puppetlabs/save/environments
cd /etc/puppetlabs/code/environmen
for x in $(ls -1 | grep -v -w -e stable -e production)
do
echo "mv -f $x /etc/puppetlabs/save/environments/"
mv -f $x /etc/puppetlabs/save/environments/
done
cd
}
enable_envs() {
# move envs to other location to speed up puppetserver restart
cd /etc/puppetlabs/save/environments
for x in $(ls -1 | grep -v -w -e stable -e production)
do
echo "mv -f $x /etc/puppetlabs/code/environments/"
mv -f $x /etc/puppetlabs/code/environments/
done
cd
rmdir /etc/puppetlabs/save/environments
}
version="2018.1.4"
disable_envs
do_upgrade "${version}" 2>&1| tee /tmp/upgrade_${version}.log
enable_envs