-
Notifications
You must be signed in to change notification settings - Fork 0
/
puppet-bootstrap.sh
executable file
·117 lines (96 loc) · 2.57 KB
/
puppet-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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Supports
# RHEL/CentOS 5.8-6.x
# Fedora 18,19,20
# Debian 6,7
# Ubuntu 10.04 (Lucid), 12.04 (Precise), 12.10 (Quantal), 13.04 (Raring), 13.10 (Saucy)
# Init Vars
ENVIRONMENT="production"
if [ $# -lt 1 ];
then
echo "Usage $0 <SERVER_IP> <ENVIRONMENT> <CUSTOMSCRIPTNAME>"
exit 2
else
SERVER_IP=$1
fi
if [ $2 ];
then
ENVIRONMENT=$2
fi
# Determain CPU
CPU=`uname -p`
# Determain version, update software, install puppet
if [ -f /etc/debian_version ]; then
OS=debian
VER=$(cat /etc/debian_version | cut -d '.' -f 1)
if [ $VER = 7 ]; then
SUB="wheezy"
elif [ $VER = 6 ]; then
SUB="squeeze"
fi
# Debian update & puppet install
if [ SUB ]; then
wget https://apt.puppetlabs.com/puppetlabs-release-$SUB.deb
dpkg -i puppetlabs-release-$SUB.deb
apt-get update
apt-get -y install puppet
fi
elif [ -f /etc/fedora-release ]; then
OS=fedora
VER=$(awk '/release/ {split($3,a,"."); print a[1];}' /etc/fedora-release)
if [ $VER = "18" ]; then
SUB=7
elif [ $VER = "19" ]; then
SUB=2
elif [ $VER = "20" ]; then
SUB=1
fi
# Fedora update & puppet install
wget https://yum.puppetlabs.com/fedora/f$VER/products/$CPU/puppetlabs-release-$VER-$SUB.noarch.rpm
rpm -Uvh puppetlabs-release-$VER-$SUB.noarch.rpm
yum update -y
yum install -y puppet
elif [ -f /etc/redhat-release ]; then
OS=rhel
VER=$(awk '/release/ {split($3,a,"."); print a[1];}' /etc/redhat-release)
# RHEL CentOS update & puppet install
wget https://yum.puppetlabs.com/el/5/products/$CPU/puppetlabs-release-$VER-7.noarch.rpm
rpm -Uvh puppetlabs-release-$VER-7.noarch.rpm
yum update -y
yum install -y puppet
elif [ -f /etc/lsb-release && !$OS ]; then
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
SUB=$DISTRIB_CODENAME
# Ubuntu update & puppet install
wget https://apt.puppetlabs.com/puppetlabs-release-$SUB.deb
dpkg -i puppetlabs-release-$SUB.deb
apt-get update
apt-get -y install puppet
fi
# update hosts to include puppet master server
cat >> /etc/hosts <<EOF
$SERVER_IP puppet
EOF
# Configure Puppet to talk to our environment
cat >> /etc/puppet/puppet.conf <<EOF
[agent]
environment = $ENVIRONMENT
EOF
# set puppet service defaults
cat > /etc/default/puppet <<EOF
# Defaults for puppet - sourced by /etc/init.d/puppet
# Start puppet on boot?
START=NO
# Startup options
DAEMON_OPTS="--environment=$ENVIRONMENT"
EOF
# Run any custom init script before starting puppet
if [ -f $3 ];
then
. $3
fi
# Start puppet agent
/usr/bin/puppet agent --environment $ENVIRONMENT
exit 0