Added vhost support

This commit is contained in:
James Fryman 2011-06-02 14:49:39 -05:00
parent 3b036c95e5
commit fe3e409c9c
14 changed files with 141 additions and 144 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
files/server_test.crt
files/server_test.pem
pkg/

17
ChangeLog Normal file
View file

@ -0,0 +1,17 @@
2011-05-24 James Fryman <james@frymanet.com>
* LICENSE, Modulefile, README, files/README.markdown,
files/centos/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL, lib/facter/README.markdown,
lib/puppet/parser/functions/README.markdown,
lib/puppet/provider/README.markdown, lib/puppet/type/README.markdown,
manifests/README.markdown, manifests/config.pp, manifests/init.pp,
manifests/install.pp, manifests/params.pp, manifests/service.pp,
manifests/vhost.pp, metadata.json, spec/README.markdown, spec/spec.opts,
spec/spec_helper.rb, spec/unit/puppet/provider/README.markdown,
spec/unit/puppet/type/README.markdown, templates/README.markdown,
templates/nginx.conf.erb, templates/vhost.pp, tests/init.pp, tests/vhost.pp:
20110524 Work Snapshot
2011-05-23 James Fryman <james@frymanet.com>
* : Initial Repository Initilization

View file

@ -1,11 +1,11 @@
name 'jfryman-nginx'
version '0.0.1'
source 'UNKNOWN'
author 'jfryman'
license 'UNKNOWN'
summary 'UNKNOWN'
description 'UNKNOWN'
project_page 'UNKNOWN'
source 'http://github.com/jfryman/puppet-nginx'
author 'James Fryman'
license 'Apache 2'
summary 'Puppet NGinX management module'
description 'This module can be used for basic NGINX Management'
project_page 'http://github.com/jfryman/puppet-nginx'
## Add dependencies, if any:
# dependency 'username/name', '>= 1.2.0'

View file

@ -1,30 +0,0 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.2.6 (GNU/Linux)
mQGiBEXopTIRBACZDBMOoFOakAjaxw1LXjeSvh/kmE35fU1rXfM7T0AV31NATCLF
l5CQiNDA4oWreDThg2Bf6+LIVTsGQb1V+XXuLak4Em5yTYwMTVB//4/nMxQEbpl/
QB2XwlJ7EQ0vW+kiPDz/7pHJ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/7h1NYRp5GQL2ZsoV4g9U2gMdzHOFtZCER6PP9ErVlfJpgBUCdSL93V4H
Sgpkk7znmTOklbCM6l/G/A6q4sCRqfzHwVSTiruyTBiU9lfROsAl8fjIq2OzWJ2T
P9sadBe1llUYaow7txYSUxssW+89avct35gIyrBbof5M+CBXyAOUaSWmpM2eub24
0qbqiSr/Y6Om0t6vSzR8gRk7g+1H6IE0Tt1IJCvCAMimiE8EGBECAA8FAkXopTYC
GwwFCRLMAwAACgkQEZzANiF1IfZQYgCgiZHCv4xb+sTHCn/otc1Ovvi/OgMAnRXY
bbsLFWOfmzAnNIGvFRWy+YHi
=MMNL
-----END PGP PUBLIC KEY BLOCK-----

View file

@ -1,32 +1,23 @@
class nginx::config {
$daemon_user = $operatingsystem ? {
/(debian|ubuntu)/ => 'www-data',
/(fedora|rhel|centos)/ => 'nginx',
class nginx::config inherits nginx::params {
File {
owner => 'root',
group => 'root',
mode => '0644',
}
user { $daemon_user:
ensure => present,
file { '/etc/nginx/sites-enabled':
ensure => directory,
}
group { $daemon_user:
ensure => present,
file { '/etc/nginx/sites-enabled/default':
ensure => absent,
}
file { '/etc/nginx/nginx.conf':
ensure => file,
owner => 'root',
group => 'root',
content => template('nginx/nginx.conf.erb'),
require => Class['nginx::install'],
notify => Class['nginx::service'],
}
file { '/etc/nginx/sites-available':
ensure => directory,
owner => 'root',
group => 'root',
require => Class['nginx::install'],
}
file { '/etc/nginx/sites-enabled':
ensure => directory,
owner => 'root',
group => 'root',
require => Class['nginx::install'],
}
}

View file

@ -12,5 +12,10 @@
#
# [Remember: No empty lines between comments and class definition]
class nginx {
include nginx::service, nginx::install, nginx::config,
include nginx::package
include nginx::config
include nginx::service
Class['nginx::package'] -> Class['nginx::config'] ~> Class['nginx::service']
}

View file

@ -1,12 +0,0 @@
class nginix::install {
# prepopulating a potential install for non-Linux distros.
$package = $operatingsystem ? {
/(ubuntu|debian|centos|fedora|rhel)/ => 'nginx'
}
package { $package:
name => 'nginx',
ensure => installed,
}
}

23
manifests/package.pp Normal file
View file

@ -0,0 +1,23 @@
class nginx::package {
package { 'nginx':
ensure => present,
}
case $operatingsystem {
rhel,centos,oel: {
package { 'GeoIP':
ensure => present,
}
package { 'gd':
ensure => present,
}
package { 'libXpm':
ensure => present,
}
package { 'libxslt':
ensure => present,
}
}
}
}

View file

@ -10,19 +10,24 @@
#######################################################################
class nginx::params {
$worker_processes = 1
$worker_connections = 1024
$multi_accept = off
$sendfile = on
$keepalive_timeout = 65
$tcp_nodelay = on
$gzip = on
$nx_worker_processes = 1
$nx_worker_connections = 1024
$nx_multi_accept = off
$nx_sendfile = on
$nx_keepalive_timeout = 65
$nx_tcp_nodelay = on
$nx_gzip = on
# Setup OS Specific Logging Directories and PID files.
case $kernel {
default {
$log_dir = '/var/log/nginx'
$pid = '/var/run/nginx.pid'
}
$nx_logdir = $kernel ? {
/(?i-mx:linux)/ => '/var/log/nginx',
}
$nx_pid = $kernel ? {
/(?i-mx:linux)/ => '/var/run/nginx.pid',
}
$nx_daemon_user = $operatingsystem ? {
/(?i-mx:debian|ubuntu)/ => 'www-data',
/(?i-mx:fedora|rhel|centos)/ => 'nginx',
}
}

View file

@ -1,9 +1,9 @@
class nginix::service {
class nginx::service {
service { "nginx":
ensure => running,
enable => true,
hasstatus => true,
hasrestart => true,
require => Class['nginx::install'],
subscribe => Class['nginx'],
}
}

View file

@ -1,25 +1,35 @@
define nginx::vhost(
$listen = '*',
$listen_port,
$www_root,
$ssl = 'off',
$ssl_cert,
$ssl_key,
$location,
$state = 'enable',
$ensure = 'enable',
$listen_ip = '*',
$listen_port = '80',
$ipv6_enable = 'false',
$ipv6_listen_ip = '::',
$ipv6_listen_port = '80',
$ssl = 'false',
$ssl_cert = undef,
$ssl_key = undef,
$index_files = ['index.html', 'index.htm', 'index.php'],
$www_root
) {
file { "/etc/nginx/sites-available/${name}":
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('nginx/vhost.erb')
}
file { "/etc/nginx/sites-enabled/${name}":
ensure => $state ? {
'disable' => absent,
default => 'symlink',
# Check to see if SSL Certificates are properly defined
if ($ssl == 'true') {
if ($ssl_cert == undef) {
fail('SSL Certificate (ssl_cert) must be defined and exist on the target system(s)')
} elsif ($ssl_key == undef) {
fail('SSL Private Key (ssl_key) must be defined and exist on the target system(s)')
}
target => "/etc/nginx/sites-available/${name}",
}
file { "/etc/nginx/sites-enabled/${name}":
ensure => $ensure ? {
'absent' => absent,
default => 'file',
},
owner => 'root',
group => 'root',
mode => '0644',
content => template('nginx/vhost.erb'),
notify => Class['nginx::service'],
}
}

View file

@ -1,12 +0,0 @@
/*
+-----------------------------------------------------------------------+
| |
| ==> DO NOT EDIT THIS FILE! <== |
| |
| You should edit the `Modulefile` and run `puppet-module build` |
| to generate the `metadata.json` file for your releases. |
| |
+-----------------------------------------------------------------------+
*/
{}

View file

@ -1,32 +1,31 @@
user <%= scope.lookupvar('nginx::config::daemon_user') %>;
worker_processes <%= scope.lookupvar('nginx::params::worker_processes')%>;
user <%= scope.lookupvar('nginx::config::nx_daemon_user') %>;
worker_processes <%= scope.lookupvar('nginx::params::nx_worker_processes')%>;
error_log <%= scope.lookupvar('nginx::params::log_dir')%>/error.log;
pid <%= scope.lookupvar('nginx::params::pid')%>;
error_log <%= scope.lookupvar('nginx::params::nx_logdir')%>/error.log;
pid <%= scope.lookupvar('nginx::params::nx_pid')%>;
events {
worker_connections <%= scope.lookupvar('nginx::params::worker_connections') %>;
<% if scope.lookupvar('nginx::params::multi_accept' == 'on') %>
multi_accept on;
<% end %>
worker_connections <%= scope.lookupvar('nginx::params::nx_worker_connections') %>;
<% if scope.lookupvar('nginx::params::nx_multi_accept' == 'on') %>multi_accept on;<% end %>
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
default_type application/octet-stream;
access_log <%= scope.lookupvar('nginx::params::log_dir')%>/access.log;
access_log <%= scope.lookupvar('nginx::params::nx_logdir')%>/access.log;
sendfile <%= scope.lookupvar('nginx::params::sendfile')%>;
<% if scope.lookupvar('nginx::params::tcp_nopush' == 'on') %>
tcp_nopush on;
<% end %>
keepalive_timeout <%= scope.lookupvar('nginx::params::keepalive_timeout')%>;
tcp_nodelay <%= scope.lookupvar('nginx::params::tcp_nodelay')%>;
sendfile <%= scope.lookupvar('nginx::params::nx_sendfile')%>;
<% if scope.lookupvar('nginx::params::gzip' == 'on') %>
gzip on;
<% if scope.lookupvar('nginx::params::nx_tcp_nopush' == 'on') %>
tcp_nopush on;
<% end %>
keepalive_timeout <%= scope.lookupvar('nginx::params::nx_keepalive_timeout')%>;
tcp_nodelay <%= scope.lookupvar('nginx::params::nx_tcp_nodelay')%>;
<% if scope.lookupvar('nginx::params::nx_gzip' == 'on') %>
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
<% end %>

View file

@ -1,19 +1,17 @@
server {
listen <%= listen %>; ## listen for ipv4
listen [::]:80 default ipv6only=on; ## listen for ipv6
listen <%= listen_ip %>;
<% if ipv6_enable == 'true' %>listen [<%= ipv6_listen_ip %>]:<%= ipv6_listen_port %> default ipv6only=on;<% end %>
server_name <%= name %>;
access_log <%= scope.lookupvar('nginx::params::log_dir')%>/<%= name %>.access.log;
access_log <%= scope.lookupvar('nginx::params::nx_logdir')%>/<%= name %>.access.log;
location / {
root <%= www_root %>;
index index.html index.htm;
index <% index_files.each do |i| %> <%= i %> <% end %>;
}
}
<% if ssl == 'on' %>
<% if ssl == 'true' %>
server {
listen 443;
server_name <%= name %>;