This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
centos6_puppetmaster_apache.sh
376 lines (319 loc) · 11.6 KB
/
centos6_puppetmaster_apache.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/usr/bin/env bash
#
# Software License Agreement (BSD License)
#
# Copyright (c) 2009-2012, Eucalyptus Systems, Inc.
# All rights reserved.
#
# Redistribution and use of this software in source and binary forms, with or
# without modification, are permitted provided that the following conditions
# are met:
#
# Redistributions of source code must retain the above
# copyright notice, this list of conditions and the
# following disclaimer.
#
# Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the
# following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Description:
# This recipe bootstraps a puppetmaster for use within a cloud instance
# or physical system. It uses puppet to bootstrap itself as a server and
# is based on the original puppet bootstrap recipe.
# It uses apache as the webserver with passenger to help puppet scale.
# It also sets up pluginsync and storedconfigs with a mysql backend.
#
# Credits:
# Tom Ellis <[email protected]>
# Greg DeKoenigsberg <[email protected]>
MYSQL_PASSWD="t3mp0rary"
PUPPET_MYSQL_PASSWD="t3mppupp3t"
YUM=`which yum`
RPM=`which rpm`
CURL=`which curl`
EPEL_PACKAGE="epel-release-6-7.noarch.rpm"
EPEL_URL="http://dl.fedoraproject.org/pub/epel/6/i386/"
PUPPETLABS_PACKAGE="puppetlabs-release-6-1.noarch.rpm"
PUPPETLABS_URL="http://yum.puppetlabs.com/el/6/products/x86_64/"
PASSENGER_PACKAGE="passenger-release.noarch.rpm"
PASSENGER_URL="http://passenger.stealthymonkeys.com/rhel/6/"
MODULE_PATH="/root/puppet/modules"
###########
# Setup the hostname for the system. Puppet really relies on
# the hostname so this must be done. The most reliable way
# is to pull it directly from the metadata service.
###########
FULL_HOSTNAME=`${CURL} http://169.254.169.254/latest/meta-data/public-hostname`
SHORT_HOST=`echo ${FULL_HOSTNAME} | cut -d'.' -f1`
hostname ${FULL_HOSTNAME}
sed -i -e "s/\(localhost.localdomain\)/${SHORT_HOST} ${FULL_HOSTNAME} \1/" /etc/hosts
sed -i -e "s/HOSTNAME.*/HOSTNAME=${FULL_HOSTNAME}/g" /etc/sysconfig/network
###########
# Download and install EPEL repo which contains lots of useful packages.
###########
curl -o /root/${EPEL_PACKAGE} ${EPEL_URL}/${EPEL_PACKAGE}
${RPM} -Uhv /root/${EPEL_PACKAGE} 1>/tmp/01.out 2>/tmp/01.err
###########
# Download and install the puppetlabs repo which has new offical releases of puppet
###########
# EPEL contains Puppet 2.6. There are some cool features in 2.7 though, ymmv.
curl -o /root/${PUPPETLABS_PACKAGE} ${PUPPETLABS_URL}/${PUPPETLABS_PACKAGE} 1>/tmp/02.out 2>/tmp/02.err
${RPM} -Uhv /root/${PUPPETLABS_PACKAGE} 1>/tmp/03.out 2>/tmp/03.err
###########
# Download and install the passenger repo to allow puppet to scale
###########
curl -o /root/${PASSENGER_PACKAGE} ${PASSENGER_URL}/${PASSENGER_PACKAGE} 1>/tmp/04.out 2>/tmp/04.err
${RPM} -Uvh /root/${PASSENGER_PACKAGE} 1>/tmp/05.out 2>/tmp/05.err
# Note that the Passenger repo doesn't like the values for $releasever that Amazon AMIs give,
# so we're going to cut those out and replace them with an explicit reference to Centos 6.
sed -i -e "s/\$releasever/6/" /etc/yum.repos.d/passenger.repo
###########
# Update the instance and install the puppet agent
###########
${YUM} -y update 1>/tmp/06.out 2>/tmp/06.err
${YUM} -y install puppet 1>/tmp/07.out 2>/tmp/07.err
##########
# Configure puppet a puppetmaster using puppet
##########
PUPPET=`which puppet`
##########
# Setup the puppet manifest in /root/puppetmaster.pp
##########
mkdir -p ${MODULE_PATH}/puppetmaster/{files,manifests} 1>/tmp/08.out 2>/tmp/08.err
cat >> ${MODULE_PATH}/puppetmaster/manifests/init.pp <<EOF
class puppetmaster {
package {
'vim-enhanced': ensure => installed
}
package {
'puppet-server': ensure => installed
}
package {
'rubygem-activerecord': ensure => installed
}
package {
'rubygem-sqlite3-ruby': ensure => installed
}
package {
'httpd': ensure => installed
}
package {
'mod_passenger': ensure => installed
}
package {
'mod_ssl': ensure => installed
}
package {
'mysql-server': ensure => installed
}
package {
'ruby-mysql': ensure => installed
}
file {'puppet.conf':
owner => 'root',
group => 'root',
mode => '0644',
path => '/etc/puppet/puppet.conf',
source => 'puppet:///modules/puppetmaster/puppet.conf',
require => Package['puppet-server'],
}
file {'puppetmaster.conf':
owner => 'root',
group => 'root',
mode => '0644',
path => '/etc/httpd/conf.d/puppetmaster.conf',
source => 'puppet:///modules/puppetmaster/puppetmaster.conf',
require => Package['mod_passenger'],
}
file {'autosign.conf':
owner => 'root',
group => 'root',
mode => '0644',
path => '/etc/puppet/autosign.conf',
source => 'puppet:///modules/puppetmaster/autosign.conf',
require => Package['puppet-server'],
}
file {'site.pp':
owner => 'root',
group => 'root',
mode => '0644',
path => '/etc/puppet/manifests/site.pp',
source => 'puppet:///modules/puppetmaster/site.pp',
require => Package['puppet-server'],
}
file {'nodes.pp':
owner => 'root',
group => 'root',
mode => '0644',
path => '/etc/puppet/manifests/nodes.pp',
source => 'puppet:///modules/puppetmaster/nodes.pp',
require => Package['puppet-server'],
}
service {
'puppetmaster':
ensure => stopped,
enable => false,
require => [ Package['puppet-server'], File['puppet.conf'], File['autosign.conf'], File['site.pp'], File['nodes.pp'] ],
}
service {
'mysqld':
ensure => running,
enable => true,
require => [ Package['mysql-server'] ],
}
service {
'httpd':
ensure => stopped,
enable => true,
require => [ Package['httpd'], Package['mod_passenger'], Package['ruby-mysql'], File['puppetmaster.conf'] ],
}
exec {'rack-config':
command => "/bin/cp -f /usr/share/puppet/ext/rack/files/config.ru /etc/puppet/rack/",
creates => "/etc/puppet/rack/config.ru",
require => File['/etc/puppet/rack/public'],
}
file {'/etc/puppet/rack/config.ru':
owner => puppet,
group => puppet,
mode => 0644,
require => Exec['rack-config'],
}
file {'/etc/puppet/rack':
owner => puppet,
group => puppet,
mode => 0644,
ensure => directory,
require => Package['puppet-server'],
}
file {'/etc/puppet/rack/public':
owner => puppet,
group => puppet,
mode => 0644,
ensure => directory,
require => File['/etc/puppet/rack'],
}
}
EOF
cat >> ${MODULE_PATH}/puppetmaster/files/puppet.conf << EOF
[main]
# The Puppet log directory.
# The default value is '\$vardir/log'.
logdir = /var/log/puppet
# Where Puppet PID files are kept.
# The default value is '\$vardir/run'.
rundir = /var/run/puppet
# Where SSL certificates are kept.
# The default value is '\$confdir/ssl'.
ssldir = \$vardir/ssl
# Pluginsync
pluginsync = true
[agent]
# The file in which puppetd stores a list of the classes
# associated with the retrieved configuratiion. Can be loaded in
# the separate ``puppet`` executable using the ``--loadclasses``
# option.
# The default value is '\$confdir/classes.txt'.
classfile = \$vardir/classes.txt
# Where puppetd caches the local configuration. An
# extension indicating the cache format is added automatically.
# The default value is '\$confdir/localconfig'.
localconfig = \$vardir/localconfig
server = ${FULL_HOSTNAME}
[master]
certname = ${FULL_HOSTNAME}
# Stored configs
storeconfigs = true
thin_storeconfigs = true
dbadapter = mysql
dbname = puppet
dbuser = puppet
dbpassword = ${PUPPET_MYSQL_PASSWD}
dbserver = localhost
# dbsocket = /var/run/mysqld/mysqld.sock
[production]
# Production environment configuration
modulepath=/etc/puppet/modules
templatedir=/var/lib/puppet/templates
manifest=/etc/puppet/manifests/site.pp
EOF
cat >> ${MODULE_PATH}/puppetmaster/files/autosign.conf <<EOF
# Change this to whitelist your DNS address e.g. *.example.com
EOF
cat >> ${MODULE_PATH}/puppetmaster/files/site.pp <<EOF
# Main Puppet site.pp
# Import our node definitions from a separate file
import 'nodes.pp'
EOF
cat >> ${MODULE_PATH}/puppetmaster/files/nodes.pp <<EOF
node default {
}
EOF
cat >> ${MODULE_PATH}/puppetmaster/files/puppetmaster.conf <<EOF
# you probably want to tune these settings
PassengerHighPerformance on
PassengerMaxPoolSize 12
PassengerPoolIdleTime 1500
# PassengerMaxRequests 1000
PassengerStatThrottleRate 120
RackAutoDetect Off
RailsAutoDetect Off
Listen 8140
<VirtualHost *:8140>
SSLEngine on
SSLProtocol -ALL +SSLv3 +TLSv1
SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP
SSLCertificateFile /var/lib/puppet/ssl/certs/${FULL_HOSTNAME}.pem
SSLCertificateKeyFile /var/lib/puppet/ssl/private_keys/${FULL_HOSTNAME}.pem
SSLCertificateChainFile /var/lib/puppet/ssl/ca/ca_crt.pem
SSLCACertificateFile /var/lib/puppet/ssl/ca/ca_crt.pem
# If Apache complains about invalid signatures on the CRL, you can try disabling
# CRL checking by commenting the next line, but this is not recommended.
SSLCARevocationFile /var/lib/puppet/ssl/ca/ca_crl.pem
SSLVerifyClient optional
SSLVerifyDepth 1
SSLOptions +StdEnvVars
# This header needs to be set if using a loadbalancer or proxy
RequestHeader unset X-Forwarded-For
RequestHeader set X-SSL-Subject %{SSL_CLIENT_S_DN}e
RequestHeader set X-Client-DN %{SSL_CLIENT_S_DN}e
RequestHeader set X-Client-Verify %{SSL_CLIENT_VERIFY}e
DocumentRoot /etc/puppet/rack/public/
RackBaseURI /
<Directory /etc/puppet/rack/>
Options None
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
EOF
############
# Apply the puppet manifest
############
$PUPPET apply --modulepath=${MODULE_PATH} -e "include puppetmaster" 1>/tmp/09.out 2>/tmp/09.err
# Cleanup
rm -rf /root/{$EPEL_PACKAGE,$PUPPETLABS_PACKAGE,$PASSENGER_PACKAGE,puppet} 1>/tmp/10.out 2>/tmp/10.err
# Set mysql root passwd
/usr/bin/mysqladmin -u root password ${MYSQL_PASSWD} 1>/tmp/11.out 2>/tmp/11.err
# Create puppetdb
mysql -u root --password=${MYSQL_PASSWD} -e "create database puppet; grant all privileges on puppet.* to puppet@localhost identified by '${PUPPET_MYSQL_PASSWD}';" 1>/tmp/12.out 2>/tmp/12.err
# We need to generate the puppet ssl certs before we can start apache
# perhaps there is a better way than doing this
/sbin/service puppetmaster start 1>/tmp/13.out 2>/tmp/13.err
/sbin/service puppetmaster stop 1>/tmp/14.out 2>/tmp/14.err
# Let's go!
/sbin/service httpd start 1>/tmp/15.out 2>/tmp/15.err