Skip to content

Commit 1a3a13d

Browse files
Tim Meuselbastelfreak
authored andcommitted
add nginx/unicorn support for puppet master on centos
this is a huge commit which adds support to install nginx on a centos7 node with unicorn backend. You can run an all-in-one node with puppet master/ca on it, or use it to configure a central ssl offloading proxy with puppet ca on it and several master backends and backups.
1 parent be1964d commit 1a3a13d

16 files changed

+484
-77
lines changed

README.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ as this module requires the passenger apache module.
1313

1414
Requires the following modules from puppetforge: [stdlib](https://forge.puppetlabs.com/puppetlabs/stdlib), [apache](https://forge.puppetlabs.com/puppetlabs/apache), [concat](https://forge.puppetlabs.com/puppetlabs/concat), [inifile](https://forge.puppetlabs.com/puppetlabs/inifile)
1515

16+
1617
## Usage Note ##
1718

1819
If you are using this module to install a puppetmaster and serving the manifest of
@@ -52,6 +53,13 @@ Puppet 3.5 introduced a new way of handling Puppet environments known as _Direct
5253

5354
Optionally, an `environmentpath` parameter can be supplied to configure the base root of Puppet environments, this defaults to `$confdir/environments`
5455

56+
### Support for httpd and nginx ###
57+
58+
class { 'puppet::master':
59+
webserver => 'nginx'
60+
}
61+
62+
The default installed webserver is httpd with passenger, but via the webserver param you can switch to nginx with unicorn (nginx is currently only tested on centos7, testers are welcome). Note that if you have selinux enabled, you must have [this](https://github.com/gavinrogers/puppet-selinux) selinux module installed.
5563

5664
## Agent ##
5765
class { 'puppet::agent':

files/nginx.selmodule

941 Bytes
Binary file not shown.

manifests/agent.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
# ['templatedir'] - Template dir, if unset it will remove the setting.
3232
# ['configtimeout'] - How long the client should wait for the configuration to be retrieved before considering it a failure
3333
# ['stringify_facts'] - Wether puppet transforms structured facts in strings or no. Defaults to true in puppet < 4, deprecated in puppet >=4 (and will default to false)
34+
# ['serialization_format'] - defaults to undef, otherwise it sets the preferred_serialization_format param (currently only msgpack is supported)
35+
# ['serialization_package'] - defaults to undef, if provided, we install this package, otherwise we fall back to the gem from 'serialization_format'
3436
# ['cron_hour'] - What hour to run if puppet_run_style is cron
3537
# ['cron_minute'] - What minute to run if puppet_run_style is cron
3638
# ['serialization_format'] - defaults to undef, otherwise it sets the preferred_serialization_format param (currently only msgpack is supported)
@@ -454,3 +456,4 @@
454456
}
455457
}
456458
}
459+

manifests/master.pp

Lines changed: 90 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
# ['puppet_ssldir'] - Puppet sll directory
2323
# ['puppet_docroot'] - Doc root to be configured in apache vhost
2424
# ['puppet_vardir'] - Vardir used by puppet
25-
# ['puppet_passenger_port'] - Port to configure passenger on default 8140
25+
# ['puppet_proxy_port'] - Port to configure the proxy on - default 8140
26+
# ['puppet_conf'] - Path to the puppet main/agent/master config
2627
# ['puppet_master_package'] - Puppet master package
2728
# ['puppet_master_service'] - Puppet master service
2829
# ['version'] - Version of the puppet master package to install
@@ -37,6 +38,15 @@
3738
# ['always_cache_features'] - if false (default), always try to load a feature even if a previous load failed
3839
# ['serialization_format'] - defaults to undef, otherwise it sets the preferred_serialization_format param (currently only msgpack is supported)
3940
# ['serialization_package'] - defaults to undef, if provided, we install this package, otherwise we fall back to the gem from 'serialization_format'
41+
# ['webserver'] - install 'nginx' (with unicorn) or 'httpd' (with passenger) - httpd is default
42+
# ['listen_address'] - IP for binding the webserver, defaults to *
43+
# ['disable_ssl'] - Disables SSL on the webserver. usefull if you use this master behind a loadbalancer. currently only supported by nginx, defaults to undef
44+
# ['backup_upstream'] - specify another puppet master as fallback. currently only supported by nginx
45+
# ['unicorn_package'] - package name of a unicorn rpm. if provided we install it, otherwise we built it via gem/gcc
46+
# ['unicorn_path'] - custom path to the unicorn binary
47+
# ['disable_master'] - this disables the normal master, the server will only act as a CA, currently only supported by nginx
48+
# ['upstream'] - define additional masters reachable via tcp as an array, currently only supported by nginx
49+
# ['backend_process_number'] - number of processes to start on the backebd webserver (unicorn/passenger), currently only supported by unicorn
4050
#
4151
# Requires:
4252
#
@@ -77,7 +87,7 @@
7787
$puppet_ssldir = $::puppet::params::puppet_ssldir,
7888
$puppet_docroot = $::puppet::params::puppet_docroot,
7989
$puppet_vardir = $::puppet::params::puppet_vardir,
80-
$puppet_passenger_port = $::puppet::params::puppet_passenger_port,
90+
$puppet_proxy_port = $::puppet::params::puppet_proxy_port,
8191
$puppet_passenger_tempdir = false,
8292
$puppet_passenger_cfg_addon = '',
8393
$puppet_master_package = $::puppet::params::puppet_master_package,
@@ -99,7 +109,17 @@
99109
$passenger_max_requests = 10000,
100110
$passenger_stat_throttle_rate = 30,
101111
$serialization_format = undef,
102-
$serialization_package = undef,
112+
$serialization_package = undef,
113+
$webserver = $::puppet::params::default_webserver,
114+
$listen_address = $::puppet::params::listen_address,
115+
$disable_ssl = $::puppet::params::disable_ssl,
116+
$backup_upstream = $::puppet::params::backup_upstream,
117+
$unicorn_path = $::puppet::params::unicorn_path,
118+
$unicorn_package = $::puppet::params::unicorn_package,
119+
$disable_master = $::puppet::params::disable_master,
120+
$upstream = $::puppet::params::upstream,
121+
$backend_process_number = $::puppet::params::backend_process_number,
122+
103123
) inherits puppet::params {
104124

105125
anchor { 'puppet::master::begin': }
@@ -135,28 +155,49 @@
135155
ensure => $version,
136156
}
137157
}
158+
case $webserver {
159+
nginx: {
160+
Anchor['puppet::master::begin'] ->
161+
class {'puppet::unicorn':
162+
certname => $certname,
163+
puppet_conf => $puppet_conf,
164+
puppet_ssldir => $puppet_ssldir,
165+
dns_alt_names => $dns_alt_names,
166+
listen_address => $listen_address,
167+
puppet_proxy_port => $puppet_proxy_port,
168+
disable_ssl => $disable_ssl,
169+
backup_upstream => $backup_upstream,
170+
unicorn_package => $unicorn_package,
171+
unicorn_path => $unicorn_path,
172+
disable_master => $disable_master,
173+
upstream => $upstream,
174+
backend_process_number => $backend_process_number,
175+
} ->
176+
Anchor['puppet::master::end']
177+
}
178+
default: {
179+
Anchor['puppet::master::begin'] ->
180+
class {'puppet::passenger':
181+
puppet_proxy_port => $puppet_proxy_port,
182+
puppet_docroot => $puppet_docroot,
183+
apache_serveradmin => $apache_serveradmin,
184+
puppet_conf => $::puppet::params::puppet_conf,
185+
puppet_ssldir => $puppet_ssldir,
186+
certname => $certname,
187+
conf_dir => $::puppet::params::confdir,
188+
dns_alt_names => join($dns_alt_names,','),
189+
generate_ssl_certs => $generate_ssl_certs,
190+
puppet_passenger_tempdir => $puppet_passenger_tempdir,
191+
config_addon => $puppet_passenger_cfg_addon,
192+
passenger_max_pool_size => $passenger_max_pool_size,
193+
passenger_high_performance => $passenger_high_performance,
194+
passenger_max_requests => $passenger_max_requests,
195+
passenger_stat_throttle_rate => $passenger_stat_throttle_rate,
138196

139-
Anchor['puppet::master::begin'] ->
140-
class {'puppet::passenger':
141-
puppet_passenger_port => $puppet_passenger_port,
142-
puppet_docroot => $puppet_docroot,
143-
apache_serveradmin => $apache_serveradmin,
144-
puppet_conf => $::puppet::params::puppet_conf,
145-
puppet_ssldir => $puppet_ssldir,
146-
certname => $certname,
147-
conf_dir => $::puppet::params::confdir,
148-
dns_alt_names => join($dns_alt_names,','),
149-
generate_ssl_certs => $generate_ssl_certs,
150-
puppet_passenger_tempdir => $puppet_passenger_tempdir,
151-
config_addon => $puppet_passenger_cfg_addon,
152-
passenger_max_pool_size => $passenger_max_pool_size,
153-
passenger_high_performance => $passenger_high_performance,
154-
passenger_max_requests => $passenger_max_requests,
155-
passenger_stat_throttle_rate => $passenger_stat_throttle_rate,
156-
157-
} ->
158-
Anchor['puppet::master::end']
159-
197+
} ->
198+
Anchor['puppet::master::end']
199+
}
200+
}
160201
service { $puppet_master_service:
161202
ensure => stopped,
162203
enable => false,
@@ -170,12 +211,12 @@
170211
require => File[$::puppet::params::confdir],
171212
owner => $::puppet::params::puppet_user,
172213
group => $::puppet::params::puppet_group,
173-
notify => Service['httpd'],
214+
notify => Service[$webserver],
174215
}
175216
}
176217
else {
177218
File<| title == $::puppet::params::puppet_conf |> {
178-
notify => Service['httpd'],
219+
notify => Service[$webserver],
179220
}
180221
}
181222

@@ -186,12 +227,12 @@
186227
require => Package[$puppet_master_package],
187228
owner => $::puppet::params::puppet_user,
188229
group => $::puppet::params::puppet_group,
189-
notify => Service['httpd'],
230+
notify => Service[$webserver],
190231
}
191232
}
192233
else {
193234
File<| title == $::puppet::params::confdir |> {
194-
notify +> Service['httpd'],
235+
notify +> Service[$webserver],
195236
require +> Package[$puppet_master_package],
196237
}
197238
}
@@ -200,7 +241,7 @@
200241
ensure => directory,
201242
owner => $::puppet::params::puppet_user,
202243
group => $::puppet::params::puppet_group,
203-
notify => Service['httpd'],
244+
notify => Service[$webserver],
204245
require => Package[$puppet_master_package]
205246
}
206247

@@ -209,7 +250,7 @@
209250
class { 'puppet::storeconfigs':
210251
dbserver => $storeconfigs_dbserver,
211252
dbport => $storeconfigs_dbport,
212-
puppet_service => Service['httpd'],
253+
puppet_service => Service[$webserver],
213254
puppet_confdir => $::puppet::params::confdir,
214255
puppet_conf => $::puppet::params::puppet_conf,
215256
puppet_master_package => $puppet_master_package,
@@ -223,7 +264,7 @@
223264
Ini_setting {
224265
path => $::puppet::params::puppet_conf,
225266
require => File[$::puppet::params::puppet_conf],
226-
notify => Service['httpd'],
267+
notify => Service[$webserver],
227268
section => 'master',
228269
}
229270

@@ -332,21 +373,6 @@
332373
setting => 'digest_algorithm',
333374
value => $digest_algorithm,
334375
}
335-
336-
if $strict_variables != undef {
337-
validate_bool(str2bool($strict_variables))
338-
ini_setting {'puppetmasterstrictvariables':
339-
ensure => present,
340-
setting => 'strict_variables',
341-
value => $strict_variables,
342-
}
343-
}
344-
validate_bool(str2bool($always_cache_features))
345-
ini_setting { 'puppetmasteralwayscachefeatures':
346-
ensure => present,
347-
setting => 'always_cache_features',
348-
value => $always_cache_features,
349-
}
350376
if $serialization_format != undef {
351377
if $serialization_package != undef {
352378
package { $serialization_package:
@@ -356,18 +382,18 @@
356382
if $serialization_format == 'msgpack' {
357383
unless defined(Package[$::puppet::params::ruby_dev]) {
358384
package {$::puppet::params::ruby_dev:
359-
ensure => 'latest',
385+
ensure => latest,
360386
}
361387
}
362388
unless defined(Package['gcc']) {
363389
package {'gcc':
364-
ensure => 'latest',
390+
ensure => latest,
365391
}
366392
}
367393
unless defined(Package['msgpack']) {
368394
package {'msgpack':
369-
ensure => 'latest',
370-
provider => 'gem',
395+
ensure => latest,
396+
provider => gem,
371397
require => Package[$::puppet::params::ruby_dev, 'gcc'],
372398
}
373399
}
@@ -378,5 +404,19 @@
378404
value => $serialization_format,
379405
}
380406
}
407+
if $strict_variables != undef {
408+
validate_bool(str2bool($strict_variables))
409+
ini_setting {'puppetmasterstrictvariables':
410+
ensure => present,
411+
setting => 'strict_variables',
412+
value => $strict_variables,
413+
}
414+
}
415+
validate_bool(str2bool($always_cache_features))
416+
ini_setting { 'puppetmasteralwayscachefeatures':
417+
ensure => present,
418+
setting => 'always_cache_features',
419+
value => $always_cache_features,
420+
}
381421
anchor { 'puppet::master::end': }
382422
}

manifests/params.pp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
$manifest = '/etc/puppet/manifests/site.pp'
2424
$hiera_config = '/etc/puppet/hiera.yaml'
2525
$puppet_docroot = '/etc/puppet/rack/public/'
26-
$puppet_passenger_port = '8140'
26+
$puppet_proxy_port = '8140'
27+
$puppet_passenger_tempdir = '/var/run/rubygem-passenger'
2728
$puppet_server_port = '8140'
2829
$puppet_agent_enabled = true
2930
$apache_serveradmin = 'root'
@@ -34,6 +35,15 @@
3435
$puppet_run_interval = 30
3536
$classfile = '$statedir/classes.txt'
3637
$package_provider = undef # falls back to system default
38+
$listen_address = '*'
39+
$default_webserver = 'httpd'
40+
$disable_ssl = undef
41+
$backup_upstream = []
42+
$unicorn_package = undef
43+
$unicorn_path = '/usr/local/bin/unicorn'
44+
$disable_master = false
45+
$upstream = []
46+
$backend_process_number = $::processorcount
3747

3848
# Only used when environments == directory
3949
$environmentpath = "${confdir}/environments"
@@ -90,6 +100,17 @@
90100
$puppet_vardir = '/var/lib/puppet'
91101
$puppet_ssldir = '/etc/puppet/ssl'
92102
}
103+
'Archlinux': {
104+
$puppet_master_package = 'puppet'
105+
$puppet_agent_service = 'puppet.service'
106+
$puppet_agent_package = 'puppet'
107+
$puppet_conf = '/etc/puppet/puppet.conf'
108+
$puppet_vardir = '/var/lib/puppet'
109+
$puppet_ssldir = '/var/lib/puppet/ssl'
110+
$passenger_package = 'passenger'
111+
$rack_package = 'ruby-rack'
112+
$ruby_dev = 'ruby'
113+
}
93114
default: {
94115
err('The Puppet module does not support your os')
95116
}

manifests/passenger.pp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# This class installs and configures the puppetdb terminus pacakge
44
#
55
# Parameters:
6-
# ['generate_ssl_certs'] - Generate ssl certs (false to disable)
7-
# ['puppet_passenger_port'] - The port for the virtual host
8-
# ['puppet_docroot'] - Apache documnet root
9-
# ['apache_serveradmin'] - The apache server admin
10-
# ['puppet_conf'] - The puppet config dir
11-
# ['puppet_ssldir'] - The pupet ssl dir
12-
# ['certname'] - The puppet certname
13-
# [conf_dir] - The configuration directory of the puppet install
6+
# ['puppet_proxy_port'] - The port for the virtual host
7+
# ['generate_ssl_certs'] - Generate ssl certs (false to disable)
8+
# ['puppet_docroot'] - Apache documnet root
9+
# ['apache_serveradmin'] - The apache server admin
10+
# ['puppet_conf'] - The puppet config dir
11+
# ['puppet_ssldir'] - The pupet ssl dir
12+
# ['certname'] - The puppet certname
13+
# [conf_dir] - The configuration directory of the puppet install
1414
#
1515
# Actions:
1616
# - Configures apache and passenger for puppet master use.
@@ -22,18 +22,18 @@
2222
#
2323
# Sample Usage:
2424
# class { 'puppet::passenger':
25-
# puppet_passenger_port => 8140,
26-
# puppet_docroot => '/etc/puppet/docroot',
27-
# apache_serveradmin => 'wibble',
28-
# puppet_conf => '/etc/puppet/puppet.conf',
29-
# puppet_ssldir => '/var/lib/puppet/ssl',
30-
# certname => 'puppet.example.com',
31-
# conf_dir => '/etc/puppet',
25+
# puppet_proxy_port => 8140,
26+
# puppet_docroot => '/etc/puppet/docroot',
27+
# apache_serveradmin => 'wibble',
28+
# puppet_conf => '/etc/puppet/puppet.conf',
29+
# puppet_ssldir => '/var/lib/puppet/ssl',
30+
# certname => 'puppet.example.com',
31+
# conf_dir => '/etc/puppet',
3232
# }
3333
#
3434
class puppet::passenger(
3535
$generate_ssl_certs = true,
36-
$puppet_passenger_port,
36+
$puppet_proxy_port,
3737
$puppet_passenger_tempdir = false,
3838
$puppet_docroot,
3939
$apache_serveradmin,
@@ -110,7 +110,7 @@
110110
}
111111

112112
apache::vhost { "puppet-${certname}":
113-
port => $puppet_passenger_port,
113+
port => $puppet_proxy_port,
114114
priority => '40',
115115
docroot => $puppet_docroot,
116116
serveradmin => $apache_serveradmin,
@@ -181,3 +181,4 @@
181181
require => File[$puppet_conf],
182182
}
183183
}
184+

0 commit comments

Comments
 (0)