-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-puppet-agent-redhat.sh
83 lines (75 loc) · 2.33 KB
/
install-puppet-agent-redhat.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
76
77
78
79
80
81
82
83
#!/bin/bash
# PUPPET INSTALL/RUN DETECTION
if pgrep puppet > /dev/null 2>&1; then
echo puppet is already running, not good, bye.;
exit 1;
else
echo puppet is not running, good.;
if rpm -qa | grep "puppet-" > /dev/null 2>&1; then
echo puppet is already installed, not good, bye.;
exit 1;
else
echo puppet is not yet installed, good.;
fi
fi
# VERSION DETECTION
if command -v lsb_release > /dev/null 2>&1; then
echo "installing for:";
lsb_release -a;
VERSION=`lsb_release -sr | cut -d. -f1`;
else
# Puppet agent needs this. But we can use system-release-cp for version determination too.
yum install redhat-lsb-core -y
if [ ! -f /etc/system-release-cpe ]; then
echo "Cannot determine OS release/version, not good.";
exit 1;
else
echo "Installing for: `cat /etc/system-release-cpe`";
VERSION=`cat /etc/system-release-cpe | cut -d: -f5`
fi
fi
# CLOUD-INIT HOSTNAME PRESERVATION
if [ -f /etc/cloud/cloud.cfg ]; then
echo "Cloud-init found."
echo "Removing existing preserve_hostname setting."
sed -i '/preserve_hostname/d' /etc/cloud/cloud.cfg
echo "Inserting new preserve_hostname setting."
sed -i "6a\
preserve_hostname: true" /etc/cloud/cloud.cfg
else
echo "No cloud-init found. Done."
fi
# HOSTNAME
echo "Current hostname is set to `hostnamectl status --static`."
read -n 1 -p "Do you want to change it before running puppet? [Y/n]: " "changehostname"
echo ""
if [ "$changehostname" == "y" ] || [ "$changehostname" == "Y" ]; then
read -p "What is the new hostname?: " "newhost"
echo ""
hostnamectl set-hostname $newhost
echo "Changed hostname to $newhost. Done!"
else
echo "Not changing hostname. Done."
fi
# INSTALL PUPPET
rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-el-${VERSION}.noarch.rpm
yum clean all
yum install puppet -y
# CONFIGURE PUPPET MASTER HINTS
if grep -q "84\.53\.103\.71" /etc/hosts; then
echo removing reference to old puppet master;
sed -i '/84.53.103.71/d' /etc/hosts
fi
if grep -q "149\.210\.174\.225" /etc/hosts; then
echo puppet master is already in hosts file;
else
echo "149.210.174.225 puppet.maxserv.com puppet" >> /etc/hosts;
echo puppet master added to hosts file;
fi
# BOOTSTRAP AGENT
puppet agent --waitforcert 60 --test
if [ -f /etc/init.d/puppet ]; then
/etc/init.d/puppet start
else
/bin/systemctl start puppet
fi