Skip to content

Commit 17bdf2d

Browse files
author
Tim Meusel
committed
added manage_webserver param
1 parent fea4edb commit 17bdf2d

File tree

11 files changed

+116
-49
lines changed

11 files changed

+116
-49
lines changed

Modulefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ dependency 'puppetlabs/inifile', '>= 1.0.0'
1111
dependency 'puppetlabs/apache', '>= 1.0.1'
1212
dependency 'puppetlabs/puppetdb', '>= 2.0.0'
1313
dependency 'puppetlabs/stdlib', '>= 3.0.0'
14+
dependency 'jfryman/nginx', '>= 0.1.1'

README.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ Puppet 3.5 introduced a new way of handling Puppet environments known as _Direct
5252

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

55+
### Support for httpd and nginx ###
56+
57+
class { 'puppet::master':
58+
webserver => 'nginx'
59+
}
60+
61+
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)
5562

5663
## Agent ##
5764
class { 'puppet::agent':

files/nginx.selmodule

941 Bytes
Binary file not shown.

manifests/master.pp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
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
2626
# ['puppet_master_package'] - Puppet master package
2727
# ['puppet_master_service'] - Puppet master service
2828
# ['version'] - Version of the puppet master package to install
@@ -32,7 +32,8 @@
3232
# ['puppetdb_startup_timeout'] - The timeout for puppetdb
3333
# ['dns_alt_names'] - Comma separated list of alternative DNS names
3434
# ['digest_algorithm'] - The algorithm to use for file digests.
35-
# ['webserver'] - install 'nginx' (with unicorn) or 'httpd' (with passanger)
35+
# ['webserver'] - install 'nginx' (with unicorn) or 'httpd' (with passenger) - httpd is default
36+
# ['listen_address'] - IP for binding the webserver, defaults to *
3637
#
3738
# Requires:
3839
#
@@ -73,7 +74,7 @@
7374
$puppet_ssldir = $::puppet::params::puppet_ssldir,
7475
$puppet_docroot = $::puppet::params::puppet_docroot,
7576
$puppet_vardir = $::puppet::params::puppet_vardir,
76-
$puppet_passenger_port = $::puppet::params::puppet_passenger_port,
77+
$puppet_proxy_port = $::puppet::params::puppet_proy_port,
7778
$puppet_master_package = $::puppet::params::puppet_master_package,
7879
$puppet_master_service = $::puppet::params::puppet_master_service,
7980
$version = 'present',
@@ -84,12 +85,8 @@
8485
$puppetdb_strict_validation = $::puppet::params::puppetdb_strict_validation,
8586
$dns_alt_names = ['puppet'],
8687
$digest_algorithm = $::puppet::params::digest_algorithm,
87-
<<<<<<< HEAD
88-
$webserver = 'httpd',
89-
$manage_webserver = false,
90-
=======
91-
$manage_webserver = undef,
92-
>>>>>>> trying to remove service[http] deps
88+
$webserver = $::puppet::params::default_webserver,
89+
$listen_address = $::puppet::params::listen_address,
9390
) inherits puppet::params {
9491

9592
anchor { 'puppet::master::begin': }
@@ -126,25 +123,29 @@
126123
}
127124
}
128125
case $webserver {
129-
httpd: {
126+
nginx: {
130127
Anchor['puppet::master::begin'] ->
131-
class {'puppet::passenger':
132-
puppet_passenger_port => $puppet_passenger_port,
133-
puppet_docroot => $puppet_docroot,
134-
apache_serveradmin => $apache_serveradmin,
135-
puppet_conf => $::puppet::params::puppet_conf,
136-
puppet_ssldir => $puppet_ssldir,
137-
certname => $certname,
138-
conf_dir => $::puppet::params::confdir,
139-
dns_alt_names => join($dns_alt_names,','),
128+
class {'puppet::unicorn':
129+
listen_address => $listen_address,
130+
puppet_proxy_port => $puppet_proxy_port,
140131
} ->
141132
Anchor['puppet::master::end']
142133
}
143-
nginx: {
134+
default: {
144135
Anchor['puppet::master::begin'] ->
145-
class {'puppet::unicorn':} ->
136+
class {'puppet::passenger':
137+
puppet_proxy_port => $puppet_proxy_port,
138+
puppet_docroot => $puppet_docroot,
139+
apache_serveradmin => $apache_serveradmin,
140+
puppet_conf => $::puppet::params::puppet_conf,
141+
puppet_ssldir => $puppet_ssldir,
142+
certname => $certname,
143+
conf_dir => $::puppet::params::confdir,
144+
dns_alt_names => join($dns_alt_names,','),
145+
} ->
146146
Anchor['puppet::master::end']
147147
}
148+
148149
}
149150
service { $puppet_master_service:
150151
ensure => stopped,

manifests/params.pp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
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'
2727
$puppet_server_port = '8140'
2828
$puppet_agent_enabled = true
2929
$apache_serveradmin = 'root'
3030
$parser = 'current'
3131
$puppetdb_strict_validation = true
3232
$environments = 'config'
3333
$digest_algorithm = 'md5'
34+
$listen_address = '*'
35+
$default_webserver = 'httpd'
3436

3537
# Only used when environments == directory
3638
$environmentpath = '$confdir/environments'

manifests/passenger.pp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This class installs and configures the puppetdb terminus pacakge
44
#
55
# Parameters:
6-
# ['puppet_passenger_port'] - The port for the virtual host
6+
# ['puppet_proxy_port'] - The port for the virtual host
77
# ['puppet_docroot'] - Apache documnet root
88
# ['apache_serveradmin'] - The apache server admin
99
# ['puppet_conf'] - The puppet config dir
@@ -21,17 +21,17 @@
2121
#
2222
# Sample Usage:
2323
# class { 'puppet::passenger':
24-
# puppet_passenger_port => 8140,
25-
# puppet_docroot => '/etc/puppet/docroot',
26-
# apache_serveradmin => 'wibble',
27-
# puppet_conf => '/etc/puppet/puppet.conf',
28-
# puppet_ssldir => '/var/lib/puppet/ssl',
29-
# certname => 'puppet.example.com',
30-
# conf_dir => '/etc/puppet',
24+
# puppet_proxyr_port => 8140,
25+
# puppet_docroot => '/etc/puppet/docroot',
26+
# apache_serveradmin => 'wibble',
27+
# puppet_conf => '/etc/puppet/puppet.conf',
28+
# puppet_ssldir => '/var/lib/puppet/ssl',
29+
# certname => 'puppet.example.com',
30+
# conf_dir => '/etc/puppet',
3131
# }
3232
#
3333
class puppet::passenger(
34-
$puppet_passenger_port,
34+
$puppet_proxy_port,
3535
$puppet_docroot,
3636
$apache_serveradmin,
3737
$puppet_conf,
@@ -99,7 +99,7 @@
9999
}
100100

101101
apache::vhost { "puppet-${certname}":
102-
port => $puppet_passenger_port,
102+
port => $puppet_proxy_port,
103103
priority => '40',
104104
docroot => $puppet_docroot,
105105
serveradmin => $apache_serveradmin,

manifests/unicorn.pp

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
1-
# this class installs nginx with unicorn in front of puppetmaster
2-
# tested only on centos 7
1+
# Class: puppet::unicorn
2+
#
3+
# Parameters:
4+
# ['listen_address'] - IP for binding the nginx
5+
# ['puppet_proxy_port'] - The port for the virtual host
6+
#
7+
# Actions:
8+
# - Configures nginx and unicorn for puppet master use. Tested only on CentOS 7
9+
#
10+
# Requires:
11+
# - nginx
12+
#
13+
# Sample Usage:
14+
# class {'puppet::unicorn':
15+
# listen_address => '10.250.250.1',
16+
# puppet_proxy_port => '8140',
17+
# }
18+
#
19+
# written by Tim 'bastelfreak' Meusel
20+
# with big help from Rob 'rnelson0' Nelson
321

4-
class puppet::unicorn () {
22+
class puppet::unicorn (
23+
$listen_address,
24+
$puppet_proxy_port,
25+
){
526
include nginx
627
# install unicorn
28+
unless defined(Package['ruby-devel']) {
29+
package {'ruby-devel':
30+
ensure => 'latest',
31+
}
32+
}
33+
package {'gcc':
34+
ensure => 'latest',
35+
} ->
736
package {['unicorn', 'rack']:
837
ensure => 'latest',
938
provider => 'gem',
39+
require => Package['ruby-devel'],
1040
} ->
1141
file {'copy-config':
1242
path => '/etc/puppet/config.ru',
@@ -15,39 +45,54 @@
1545
file {'unicorn-conf':
1646
path => '/etc/puppet/unicorn.conf',
1747
source => 'puppet:///modules/puppet/unicorn.conf',
18-
1948
} ->
2049
file {'unicorn-service':
2150
path => '/usr/lib/systemd/system/unicorn-puppetmaster.service',
2251
source => 'puppet:///modules/puppet/unicorn-puppetmaster.service',
2352
notify => Exec['systemd-reload'],
24-
}
53+
} ->
2554
exec{'systemd-reload':
2655
command => '/usr/bin/systemctl daemon-reload',
27-
refreshonly => 'true',
56+
refreshonly => true,
2857
notify => Service['unicorn-puppetmaster'],
29-
}
58+
} ->
3059
unless defined(Service['unicorn-puppetmaster']) {
3160
service{'unicorn-puppetmaster':
3261
ensure => 'running',
33-
enable => 'enable',
62+
enable => true,
63+
require => Exec['systemd-reload'],
64+
}
65+
}
66+
# update SELinux
67+
if $::selinux_config_mode == 'enforcing' {
68+
file{'get-SEL-policy':
69+
path => '/usr/share/selinux/targeted/nginx.pp',
70+
source => 'puppet:///modules/puppet/nginx.selmodule',
71+
} ->
72+
package {'policycoreutils':
73+
ensure => 'latest',
74+
} ->
75+
selmodule{'nginx':
76+
ensure => 'present',
77+
syncversion => true,
3478
}
3579
}
3680
# hacky vhost
3781
file {'puppetmaster-vhost':
3882
path => '/etc/nginx/sites-available/puppetmaster',
39-
source => 'puppet:///modules/puppet/puppetmaster',
83+
content => template('puppet/puppetmaster'),
4084
} ->
4185
file {'enable-puppetmaster-vhost':
42-
path => '/etc/nginx/sites-enabled/puppetmaster',
4386
ensure => 'link',
87+
path => '/etc/nginx/sites-enabled/puppetmaster',
4488
target => '/etc/nginx/sites-available/puppetmaster',
4589
notify => Service['nginx'],
46-
}
90+
} ->
4791
unless defined(Service['nginx']) {
4892
service{'nginx':
4993
ensure => 'running',
50-
enable => 'enable',
94+
enable => true,
95+
require => File['enable-puppetmaster-vhost'],
5196
}
5297
}
5398
}

spec/classes/puppet_passenger_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe 'puppet::passenger', :type => :class do
44
let (:params) do
55
{
6-
:puppet_passenger_port => '8140',
6+
:puppet_proxy_port => '8140',
77
:puppet_docroot => '/etc/puppet/rack/public/',
88
:apache_serveradmin => 'root',
99
:puppet_conf => '/etc/puppet/puppet.conf',

spec/classes/puppet_repo_puppetlabs_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
:lsbdistid => 'Ubuntu'
1111
}
1212
end
13+
let :params do
14+
{
15+
:mirror => 'http://apt.puppetlabs.com',
16+
}
17+
end
1318
it 'should contain puppetlabs apt repos' do
1419
should contain_apt__source('puppetlabs').with(
1520
:repos => 'main',
@@ -31,6 +36,12 @@
3136
:operatingsystem => 'Redhat'
3237
}
3338
end
39+
let :params do
40+
{
41+
:mirror => 'http://yum.puppetlabs.com',
42+
:priority => '1',
43+
}
44+
end
3445
it 'should add the redhat specific repoos' do
3546
should contain_yumrepo('puppetlabs').with(
3647
:baseurl => 'http://yum.puppetlabs.com/el/$releasever/products/$basearch'

files/puppetmaster renamed to templates/puppetmaster

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ upstream puppetmaster_unicorn {
66
# define our proxy for breaking up SSL
77
server {
88
ssl on;
9-
ssl_certificate /var/lib/puppet/ssl/certs/puppet.vps.hosteurope.de.pem;
10-
ssl_certificate_key /var/lib/puppet/ssl/private_keys/puppet.vps.hosteurope.de.pem;
9+
ssl_certificate /var/lib/puppet/ssl/certs/<%= @fqdn %>.pem;
10+
ssl_certificate_key /var/lib/puppet/ssl/private_keys/<%= @fqdn %>.pem;
1111
ssl_verify_client optional;
1212
ssl_client_certificate /var/lib/puppet/ssl/ca/ca_crt.pem;
1313
ssl_protocols TLSv1.2;
@@ -20,7 +20,7 @@ server {
2020
proxy_set_header X-Client-DN $ssl_client_s_dn;
2121
proxy_set_header X-SSL-Subject $ssl_client_s_dn;
2222
proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
23-
listen 10.111.2.250:8140 ssl;
23+
listen <%= @listen_address %>:<%= @puppet_proxy_port %> ssl;
2424
root /var/empty;
2525
location / {
2626
proxy_pass http://puppetmaster_unicorn;

0 commit comments

Comments
 (0)