From 0fc86b96fc264c7bd30a0bcbeb5911d47dcad70c Mon Sep 17 00:00:00 2001 From: James Fryman Date: Tue, 7 Jun 2011 10:59:13 -0500 Subject: [PATCH 01/13] Removed spec folder Removed spec folder from tree, as no internally written ruby tests are used in this module --- spec/README.markdown | 7 ------- spec/spec.opts | 6 ------ spec/spec_helper.rb | 18 ------------------ spec/unit/puppet/provider/README.markdown | 4 ---- spec/unit/puppet/type/README.markdown | 4 ---- 5 files changed, 39 deletions(-) delete mode 100644 spec/README.markdown delete mode 100644 spec/spec.opts delete mode 100644 spec/spec_helper.rb delete mode 100644 spec/unit/puppet/provider/README.markdown delete mode 100644 spec/unit/puppet/type/README.markdown diff --git a/spec/README.markdown b/spec/README.markdown deleted file mode 100644 index 286d3417d..000000000 --- a/spec/README.markdown +++ /dev/null @@ -1,7 +0,0 @@ -Specs -===== - -The Puppet project uses RSpec for testing. - -For more information on RSpec, see http://rspec.info/ - diff --git a/spec/spec.opts b/spec/spec.opts deleted file mode 100644 index 91cd6427e..000000000 --- a/spec/spec.opts +++ /dev/null @@ -1,6 +0,0 @@ ---format -s ---colour ---loadby -mtime ---backtrace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index a4aeeae23..000000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'pathname' -dir = Pathname.new(__FILE__).parent -$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib') - -require 'mocha' -require 'puppet' -gem 'rspec', '=1.2.9' -require 'spec/autorun' - -Spec::Runner.configure do |config| - config.mock_with :mocha -end - -# We need this because the RAL uses 'should' as a method. This -# allows us the same behaviour but with a different method name. -class Object - alias :must :should -end diff --git a/spec/unit/puppet/provider/README.markdown b/spec/unit/puppet/provider/README.markdown deleted file mode 100644 index 702585021..000000000 --- a/spec/unit/puppet/provider/README.markdown +++ /dev/null @@ -1,4 +0,0 @@ -Provider Specs -============== - -Define specs for your providers under this directory. diff --git a/spec/unit/puppet/type/README.markdown b/spec/unit/puppet/type/README.markdown deleted file mode 100644 index 1ee19ac84..000000000 --- a/spec/unit/puppet/type/README.markdown +++ /dev/null @@ -1,4 +0,0 @@ -Resource Type Specs -=================== - -Define specs for your resource types in this directory. From 594f07ef734909318d23743f4fd8f5cfc5410edd Mon Sep 17 00:00:00 2001 From: James Fryman Date: Tue, 7 Jun 2011 11:00:01 -0500 Subject: [PATCH 02/13] Updated PuppetDoc header information Updated nginx::package::suse PuppetDoc header information to accurately reflect the requirement for all packages as defined within the RPM spec for SuSE and OpenSUSE --- manifests/package/suse.pp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manifests/package/suse.pp b/manifests/package/suse.pp index dc208dc59..b3da56771 100644 --- a/manifests/package/suse.pp +++ b/manifests/package/suse.pp @@ -7,7 +7,9 @@ # There are no default parameters for this class. # # Actions: -# +# This module contains all of the required package for SuSE. Apache and all +# other packages listed below are built into the packaged RPM spec for +# SuSE and OpenSuSE. # Requires: # # Sample Usage: @@ -68,4 +70,4 @@ package { "rubygem-spruz": ensure => installed, } -} \ No newline at end of file +} From 8798816752d6b4f24beed505df9d9521dd262cff Mon Sep 17 00:00:00 2001 From: James Fryman Date: Tue, 7 Jun 2011 11:01:43 -0500 Subject: [PATCH 03/13] Updated Markup for README.markup Markup file for GitHub was not rendering text properly for third code example --- README.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 8634c7726..be66e80d7 100644 --- a/README.markdown +++ b/README.markdown @@ -23,6 +23,7 @@ Setup a new virtual host } Add a Proxy Server(s) + node default { class { 'mcollective': } nginx::resource::upstream { 'puppet_rack_app': @@ -37,4 +38,4 @@ Add a Proxy Server(s) ensure => present, proxy => 'http://puppet_rack_app', } - } \ No newline at end of file + } From 79243391ea8a51bcef82b057549f7170bd2679ba Mon Sep 17 00:00:00 2001 From: James Fryman Date: Tue, 7 Jun 2011 11:04:04 -0500 Subject: [PATCH 04/13] Updated README.markdown --- README.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/README.markdown b/README.markdown index be66e80d7..c47a27e62 100644 --- a/README.markdown +++ b/README.markdown @@ -34,6 +34,7 @@ Add a Proxy Server(s) 'localhost:3002', ], } + nginx::resource::vhost { 'rack.puppetlabs.com': ensure => present, proxy => 'http://puppet_rack_app', From 3e380e242bfa997fd3375ed23c15b6167befd239 Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Tue, 14 Jun 2011 20:02:17 -0700 Subject: [PATCH 05/13] Add transitive relationships to Class['nginx'] Without this change, the end user of the module may run into issues establishing relationships to the composite class (the main nginx class) For example, the user may declare this relationship expecting nginx to be managed after the yum repositories have been configured: node default { class { 'site::yumconfig': } -> class { 'nginx': } } However, all of the resources exist in implementation classes, which do not have a transitive relationship declared to the nginx class. Without this change, Puppet may very well manage Class['nginx::config'] before Class['site::yumconfig'] even though the user clearly indicated this should not be the case. --- manifests/init.pp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index 19ce72cf5..8764c27b5 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -29,4 +29,9 @@ include nginx::service Class['nginx::package'] -> Class['nginx::config'] ~> Class['nginx::service'] + # Allow the end user to establish relationships to the "main" class + # and preserve the relationship to the implementation classes through + # a transitive relationship to the composite class. + Class['nginx::service'] -> Class['nginx'] + } From 694ad98986f17deefe888e2547a971b6ceaad809 Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Tue, 14 Jun 2011 20:02:55 -0700 Subject: [PATCH 06/13] Whitespace only removal of tabs and trailing spaces Watch out for tab characters. =) --- manifests/init.pp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 8764c27b5..ecfb9f0d8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -3,7 +3,7 @@ # This module manages NGINX. # # Parameters: -# +# # There are no default parameters for this class. All module parameters are managed # via the nginx::params class # @@ -24,11 +24,13 @@ # include nginx # } class nginx { - include nginx::package - include nginx::config - include nginx::service - - Class['nginx::package'] -> Class['nginx::config'] ~> Class['nginx::service'] + + include nginx::package + include nginx::config + include nginx::service + + Class['nginx::package'] -> Class['nginx::config'] ~> Class['nginx::service'] + # Allow the end user to establish relationships to the "main" class # and preserve the relationship to the implementation classes through # a transitive relationship to the composite class. From 3a27502ba9e7369bd3840b3f7eb7729f9e135b7e Mon Sep 17 00:00:00 2001 From: Cody Herriges Date: Wed, 15 Jun 2011 12:40:42 -0700 Subject: [PATCH 07/13] Style compliance This commit puts the majority of the code provided by this module into compliance with the published style guide. Also updated Modulefile to have more sane pre-release values. --- Modulefile | 11 +-- manifests/config.pp | 102 +++++++++---------- manifests/package.pp | 12 +-- manifests/package/debian.pp | 12 +-- manifests/package/redhat.pp | 25 ++--- manifests/package/suse.pp | 72 +++----------- manifests/params.pp | 78 ++++++++------- manifests/resource/location.pp | 109 +++++++++++---------- manifests/resource/upstream.pp | 41 ++++---- manifests/resource/vhost.pp | 172 ++++++++++++++++----------------- manifests/service.pp | 12 +-- 11 files changed, 297 insertions(+), 349 deletions(-) diff --git a/Modulefile b/Modulefile index 9961e27a9..406078985 100644 --- a/Modulefile +++ b/Modulefile @@ -1,9 +1,8 @@ -name 'jfryman-nginx' +name 'puppetlabs-nginx' version '0.0.1' -source 'http://github.com/jfryman/puppet-nginx' -author 'James Fryman' -license 'Apache 2' +source 'http://github.com/puppetlabs/puppetlabs-nginx' +author 'puppetlabs' +license 'Apache License Version 2.0' summary 'Puppet NGINX management module' description 'This module can be used for basic NGINX Management' -project_page 'http://github.com/jfryman/puppet-nginx' - +project_page 'http://github.com/puppetlabs/puppetlabs-nginx' diff --git a/manifests/config.pp b/manifests/config.pp index 10da32fee..c6135fdb0 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -3,8 +3,8 @@ # This module manages NGINX bootstrap and configuration # # Parameters: -# -# There are no default parameters for this class. +# +# There are no default parameters for this class. # # Actions: # @@ -13,52 +13,52 @@ # Sample Usage: # # This class file is not called directly -class nginx::config inherits nginx::params { - File { - owner => 'root', - group => 'root', - mode => '0644', - } - - file { "${nginx::params::nx_conf_dir}": - ensure => directory, - } - - file { "${nginx::params::nx_conf_dir}/conf.d": - ensure => directory, - } - - file { "${nginx::config::nx_run_dir}": - ensure => directory, - } - - file { "${nginx::config::nx_client_body_temp_path}": - ensure => directory, - owner => $nginx::params::nx_daemon_user, - } - - file {"${nginx::config::nx_proxy_temp_path}": - ensure => directory, - owner => $nginx::params::nx_daemon_user, - } - - file { '/etc/nginx/sites-enabled/default': - ensure => absent, - } - - file { "${nginx::params::nx_conf_dir}/nginx.conf": - ensure => file, - content => template('nginx/conf.d/nginx.conf.erb'), - } - - file { "${nginx::params::nx_conf_dir}/conf.d/proxy.conf": - ensure => file, - content => template('nginx/conf.d/proxy.conf.erb'), - } - - file { "${nginx::config::nx_temp_dir}/nginx.d": - ensure => directory, - purge => true, - recurse => true, - } -} \ No newline at end of file +class nginx::config inherits nginx::params { + File { + owner => 'root', + group => 'root', + mode => '0644', + } + + file { "${nginx::params::nx_conf_dir}": + ensure => directory, + } + + file { "${nginx::params::nx_conf_dir}/conf.d": + ensure => directory, + } + + file { "${nginx::config::nx_run_dir}": + ensure => directory, + } + + file { "${nginx::config::nx_client_body_temp_path}": + ensure => directory, + owner => $nginx::params::nx_daemon_user, + } + + file {"${nginx::config::nx_proxy_temp_path}": + ensure => directory, + owner => $nginx::params::nx_daemon_user, + } + + file { '/etc/nginx/sites-enabled/default': + ensure => absent, + } + + file { "${nginx::params::nx_conf_dir}/nginx.conf": + ensure => file, + content => template('nginx/conf.d/nginx.conf.erb'), + } + + file { "${nginx::params::nx_conf_dir}/conf.d/proxy.conf": + ensure => file, + content => template('nginx/conf.d/proxy.conf.erb'), + } + + file { "${nginx::config::nx_temp_dir}/nginx.d": + ensure => directory, + purge => true, + recurse => true, + } +} diff --git a/manifests/package.pp b/manifests/package.pp index 988b933c0..5258c6f17 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -3,8 +3,8 @@ # This module manages NGINX package installation # # Parameters: -# -# There are no default parameters for this class. +# +# There are no default parameters for this class. # # Actions: # @@ -16,13 +16,13 @@ class nginx::package { case $operatingsystem { centos,fedora,rhel: { - include nginx::package::redhat + include nginx::package::redhat } debian,ubuntu: { - include nginx::package::debian + include nginx::package::debian } opensuse,suse: { - include nginx::package::suse + include nginx::package::suse } } -} \ No newline at end of file +} diff --git a/manifests/package/debian.pp b/manifests/package/debian.pp index c0a730881..760bdb9e6 100644 --- a/manifests/package/debian.pp +++ b/manifests/package/debian.pp @@ -3,8 +3,8 @@ # This module manages NGINX package installation on debian based systems # # Parameters: -# -# There are no default parameters for this class. +# +# There are no default parameters for this class. # # Actions: # @@ -14,7 +14,7 @@ # # This class file is not called directly class nginx::package::debian { - package { 'nginx': - ensure => present, - } -} \ No newline at end of file + package { 'nginx': + ensure => present, + } +} diff --git a/manifests/package/redhat.pp b/manifests/package/redhat.pp index 420a7fc9d..c866029ef 100644 --- a/manifests/package/redhat.pp +++ b/manifests/package/redhat.pp @@ -3,8 +3,8 @@ # This module manages NGINX package installation on RedHat based systems # # Parameters: -# -# There are no default parameters for this class. +# +# There are no default parameters for this class. # # Actions: # @@ -14,19 +14,8 @@ # # This class file is not called directly class nginx::package::redhat { - package { 'nginx': - ensure => present, - } - package { 'GeoIP': - ensure => present, - } - package { 'gd': - ensure => present, - } - package { 'libXpm': - ensure => present, - } - package { 'libxslt': - ensure => present, - } -} \ No newline at end of file + $redhat_packages = ['nginx', 'GeoIP', 'gd', 'libXpm', 'libxslt'] + package { $redhat_packages: + ensure => present, + } +} diff --git a/manifests/package/suse.pp b/manifests/package/suse.pp index b3da56771..e8748485a 100644 --- a/manifests/package/suse.pp +++ b/manifests/package/suse.pp @@ -3,71 +3,27 @@ # This module manages NGINX package installation for SuSE based systems # # Parameters: -# -# There are no default parameters for this class. +# +# There are no default parameters for this class. # # Actions: # This module contains all of the required package for SuSE. Apache and all -# other packages listed below are built into the packaged RPM spec for -# SuSE and OpenSuSE. +# other packages listed below are built into the packaged RPM spec for +# SuSE and OpenSuSE. # Requires: # # Sample Usage: # # This class file is not called directly class nginx::package::suse { - package { 'nginx-0.8': - ensure => present, - } - package { 'apache2': - ensure => present, - } - package { 'apache2-itk': - ensure => present, - } - package { 'apache2-utils': - ensure => present, - } - package { 'gd': - ensure => present, - } - package { "libapr1": - ensure => installed, - } - package { "libapr-util1": - ensure => installed, - } - package { "libjpeg62": - ensure => installed, - } - package { "libpng14-14": - ensure => installed, - } - package { "libxslt": - ensure => installed, - } - package { "rubygem-daemon_controller": - ensure => installed, - } - package { "rubygem-fastthread": - ensure => installed, - } - package { "rubygem-file-tail": - ensure => installed, - } - package { "rubygem-passenger": - ensure => installed, - } - package { "rubygem-passenger-nginx": - ensure => installed, - } - package { "rubygem-rack": - ensure => installed, - } - package { "rubygem-rake": - ensure => installed, - } - package { "rubygem-spruz": - ensure => installed, - } + $suse_packages = [ + 'nginx-0.8', 'apache2', 'apache2-itk', 'apache2-utils', 'gd', 'libapr1', + 'libapr-util1', 'libjpeg62', 'libpng14-14', 'libxslt', 'rubygem-daemon_controller', + 'rubygem-fastthread', 'rubygem-file-tail', 'rubygem-passenger', + 'rubygem-passenger-nginx', 'rubygem-rack', 'rubygem-rake', 'rubygem-spruz', + ] + + package { $suse_packages: + ensure => present, + } } diff --git a/manifests/params.pp b/manifests/params.pp index f71caef7f..7172b8a29 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -3,8 +3,8 @@ # This module manages NGINX paramaters # # Parameters: -# -# There are no default parameters for this class. +# +# There are no default parameters for this class. # # Actions: # @@ -14,39 +14,43 @@ # # This class file is not called directly class nginx::params { - $nx_temp_dir = '/tmp' - $nx_run_dir = '/var/nginx' + $nx_temp_dir = '/tmp' + $nx_run_dir = '/var/nginx' + + $nx_conf_dir = '/etc/nginx' + $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 + + $nx_proxy_redirect = off + $nx_proxy_set_header = [ + 'Host $host', 'X-Real-IP $remote_addr', + 'X-Forwarded-For $proxy_add_x_forwarded_for', + ] + + $nx_client_body_temp_path = "${nx_run_dir}/client_body_temp" + $nx_client_body_buffer_size = '128k' + $nx_client_max_body_size = '10m' + $nx_proxy_temp_path = "${nx_run_dir}/proxy_temp" + $nx_proxy_connect_timeout = '90' + $nx_proxy_send_timeout = '90' + $nx_proxy_read_timeout = '90' + $nx_proxy_buffers = '32 4k' + + $nx_logdir = $kernel ? { + /(?i-mx:linux)/ => '/var/log/nginx', + } + + $nx_pid = $kernel ? { + /(?i-mx:linux)/ => '/var/run/nginx.pid', + } - $nx_conf_dir = '/etc/nginx' - $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 - - $nx_proxy_redirect = off - $nx_proxy_set_header = ['Host $host', 'X-Real-IP $remote_addr', 'X-Forwarded-For $proxy_add_x_forwarded_for'] - $nx_client_body_temp_path = "${nx_run_dir}/client_body_temp" - $nx_client_body_buffer_size = '128k' - $nx_client_max_body_size = '10m' - $nx_proxy_temp_path = "${nx_run_dir}/proxy_temp" - $nx_proxy_connect_timeout = '90' - $nx_proxy_send_timeout = '90' - $nx_proxy_read_timeout = '90' - $nx_proxy_buffers = '32 4k' - - $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|suse|opensuse)/ => 'nginx', - } -} \ No newline at end of file + $nx_daemon_user = $operatingsystem ? { + /(?i-mx:debian|ubuntu)/ => 'www-data', + /(?i-mx:fedora|rhel|centos|suse|opensuse)/ => 'nginx', + } +} diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index 78941ae78..1e650b943 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -24,59 +24,58 @@ # location => '/bob', # vhost => 'test2.local', # } -define nginx::resource::location( - $ensure = 'present', - $vhost = undef, - $location, - $www_root = undef, - $index_files = ['index.html', 'index.htm', 'index.php'], - $proxy = undef, - $ssl = 'false', - $option = undef -){ - File { - owner => 'root', - group => 'root', - mode => '0644', - notify => Class['nginx::service'], - } - - ## Shared Variables - $ensure_real = $ensure ? { - 'absent' => absent, - default => 'file', - } - - # Use proxy template if $proxy is defined, otherwise use directory template. - if ($proxy != undef) { - $content_real = template('nginx/vhost/vhost_location_proxy.erb') - } else { - $content_real = template('nginx/vhost/vhost_location_directory.erb') - } - - ## Check for various error condtiions - if ($vhost == undef) { - fail('Cannot create a location reference without attaching to a virtual host') - } - if (($www_root == undef) and ($proxy == undef)) { - fail('Cannot create a location reference without a www_root or proxy defined') - } - if (($www_root != undef) and ($proxy != undef)) { - fail('Cannot define both directory and proxy in a virtual host') - } - - - ## Create stubs for vHost File Fragment Pattern - file {"${nginx::config::nx_temp_dir}/nginx.d/${vhost}-500-${name}": - ensure => $ensure_real, - content => $content_real, - } - - ## Only create SSL Specific locations if $ssl is true. - if ($ssl == 'true') { - file {"${nginx::config::nx_temp_dir}/nginx.d/${vhost}-800-${name}-ssl": - ensure => $ensure_real, - content => $content_re, - } +define nginx::resource::location( + $ensure = present, + $vhost = undef, + $www_root = undef, + $index_files = ['index.html', 'index.htm', 'index.php'], + $proxy = undef, + $ssl = false, + $option = undef, + $location +) { + File { + owner => 'root', + group => 'root', + mode => '0644', + notify => Class['nginx::service'], + } + + ## Shared Variables + $ensure_real = $ensure ? { + 'absent' => absent, + default => file, + } + + # Use proxy template if $proxy is defined, otherwise use directory template. + if ($proxy != undef) { + $content_real = template('nginx/vhost/vhost_location_proxy.erb') + } else { + $content_real = template('nginx/vhost/vhost_location_directory.erb') + } + + ## Check for various error condtiions + if ($vhost == undef) { + fail('Cannot create a location reference without attaching to a virtual host') + } + if (($www_root == undef) and ($proxy == undef)) { + fail('Cannot create a location reference without a www_root or proxy defined') + } + if (($www_root != undef) and ($proxy != undef)) { + fail('Cannot define both directory and proxy in a virtual host') + } + + ## Create stubs for vHost File Fragment Pattern + file {"${nginx::config::nx_temp_dir}/nginx.d/${vhost}-500-${name}": + ensure => $ensure_real, + content => $content_real, + } + + ## Only create SSL Specific locations if $ssl is true. + if ($ssl == 'true') { + file {"${nginx::config::nx_temp_dir}/nginx.d/${vhost}-800-${name}-ssl": + ensure => $ensure_real, + content => $content_real, } -} \ No newline at end of file + } +} diff --git a/manifests/resource/upstream.pp b/manifests/resource/upstream.pp index 30fc13850..acb042783 100644 --- a/manifests/resource/upstream.pp +++ b/manifests/resource/upstream.pp @@ -14,26 +14,27 @@ # nginx::resource::upstream { 'proxypass': # ensure => present, # members => [ -# 'localhost:3000', -# 'localhost:3001', -# 'localhost:3002', +# 'localhost:3000', +# 'localhost:3001', +# 'localhost:3002', # ], # } define nginx::resource::upstream ( - $ensure = 'present', - $members -){ - File { - owner => 'root', - group => 'root', - mode => '0644', - } - file { "/etc/nginx/conf.d/${name}-upstream.conf": - ensure => $ensure ? { - 'absent' => absent, - default => 'file', - }, - content => template('nginx/conf.d/upstream.erb'), - notify => Class['nginx::service'], - } -} \ No newline at end of file + $ensure = 'present', + $members +) { + File { + owner => 'root', + group => 'root', + mode => '0644', + } + + file { "/etc/nginx/conf.d/${name}-upstream.conf": + ensure => $ensure ? { + 'absent' => absent, + default => 'file', + }, + content => template('nginx/conf.d/upstream.erb'), + notify => Class['nginx::service'], + } +} diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 1c2adda8f..41ba7427d 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -6,7 +6,7 @@ # [*ensure*] - Enables or disables the specified location (present|absent) # [*listen_ip*] - Default IP Address for NGINX to listen with this vHost on. Defaults to all interfaces (*) # [*listen_port*] - Default IP Port for NGINX to listen with this vHost on. Defaults to TCP 80 -# [*ipv6_enable*] - BOOL value to enable/disable IPv6 support (false|true). Module will check to see if IPv6 +# [*ipv6_enable*] - BOOL value to enable/disable IPv6 support (false|true). Module will check to see if IPv6 # support exists on your system before enabling. # [*ipv6_listen_ip*] - Default IPv6 Address for NGINX to listen with this vHost on. Defaults to all interfaces (::) # [*ipv6_listen_port*] - Default IPv6 Port for NGINX to listen with this vHost on. Defaults to TCP 80 @@ -15,7 +15,7 @@ # with nginx::resource::upstream # [*ssl*] - Indicates whether to setup SSL bindings for this location. # [*ssl_cert*] - Pre-generated SSL Certificate file to reference for SSL Support. This is not generated by this module. -# [*ssl_key*] - Pre-generated SSL Key file to reference for SSL Support. This is not generated by this module. +# [*ssl_key*] - Pre-generated SSL Key file to reference for SSL Support. This is not generated by this module. # [*www_root*] - Specifies the location on disk for files to be read from. Cannot be set in conjunction with $proxy # # Actions: @@ -31,88 +31,88 @@ # ssl_key => '/tmp/server.pem', # } define nginx::resource::vhost( - $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, - $proxy = undef, - $index_files = ['index.html', 'index.htm', 'index.php'], - $www_root = undef + $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, + $proxy = undef, + $index_files = ['index.html', 'index.htm', 'index.php'], + $www_root = undef ) { - - File { - owner => 'root', - group => 'root', - mode => '0644', - } - - # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled - # and support does not exist for it in the kernel. - if ($ipv6_enable == 'true') and ($ipaddress6) { - warning('nginx: IPv6 support is not enabled or configured properly') - } - - # Check to see if SSL Certificates are properly defined. - if ($ssl == 'true') { - if ($ssl_cert == undef) or ($ssl_key == undef) { - fail('nginx: SSL certificate/key (ssl_cert/ssl_cert) and/or SSL Private must be defined and exist on the target system(s)') - } - } - - # Use the File Fragment Pattern to construct the configuration files. - # Create the base configuration file reference. - file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-001": - ensure => $ensure ? { - 'absent' => absent, - default => 'file', - }, - content => template('nginx/vhost/vhost_header.erb'), - notify => Class['nginx::service'], - } - - # Create the default location reference for the vHost - nginx::resource::location {"${name}-default": - ensure => $ensure, - vhost => $name, - ssl => $ssl, - location => '/', - proxy => $proxy, - www_root => $www_root, - notify => Class['nginx::service'], - } - - # Create a proper file close stub. - file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-699": - ensure => $ensure ? { - 'absent' => absent, - default => 'file', - }, - content => template('nginx/vhost/vhost_footer.erb'), - notify => Class['nginx::service'], - } - - # Create SSL File Stubs if SSL is enabled - if ($ssl == 'true') { - file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-700-ssl": - ensure => $ensure ? { - 'absent' => absent, - default => 'file', - }, - content => template('nginx/vhost/vhost_ssl_header.erb'), - notify => Class['nginx::service'], - } - file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-999-ssl": - ensure => $ensure ? { - 'absent' => absent, - default => 'file', - }, - content => template('nginx/vhost/vhost_footer.erb'), - notify => Class['nginx::service'], - } - } -} \ No newline at end of file + + File { + owner => 'root', + group => 'root', + mode => '0644', + } + + # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled + # and support does not exist for it in the kernel. + if ($ipv6_enable == 'true') and ($ipaddress6) { + warning('nginx: IPv6 support is not enabled or configured properly') + } + + # Check to see if SSL Certificates are properly defined. + if ($ssl == 'true') { + if ($ssl_cert == undef) or ($ssl_key == undef) { + fail('nginx: SSL certificate/key (ssl_cert/ssl_cert) and/or SSL Private must be defined and exist on the target system(s)') + } + } + + # Use the File Fragment Pattern to construct the configuration files. + # Create the base configuration file reference. + file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-001": + ensure => $ensure ? { + 'absent' => absent, + default => 'file', + }, + content => template('nginx/vhost/vhost_header.erb'), + notify => Class['nginx::service'], + } + + # Create the default location reference for the vHost + nginx::resource::location {"${name}-default": + ensure => $ensure, + vhost => $name, + ssl => $ssl, + location => '/', + proxy => $proxy, + www_root => $www_root, + notify => Class['nginx::service'], + } + + # Create a proper file close stub. + file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-699": + ensure => $ensure ? { + 'absent' => absent, + default => 'file', + }, + content => template('nginx/vhost/vhost_footer.erb'), + notify => Class['nginx::service'], + } + + # Create SSL File Stubs if SSL is enabled + if ($ssl == 'true') { + file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-700-ssl": + ensure => $ensure ? { + 'absent' => absent, + default => 'file', + }, + content => template('nginx/vhost/vhost_ssl_header.erb'), + notify => Class['nginx::service'], + } + file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-999-ssl": + ensure => $ensure ? { + 'absent' => absent, + default => 'file', + }, + content => template('nginx/vhost/vhost_footer.erb'), + notify => Class['nginx::service'], + } + } +} diff --git a/manifests/service.pp b/manifests/service.pp index b50b0f423..ee0f91f77 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -3,8 +3,8 @@ # This module manages NGINX service management and vhost rebuild # # Parameters: -# -# There are no default parameters for this class. +# +# There are no default parameters for this class. # # Actions: # @@ -21,11 +21,11 @@ } service { "nginx": ensure => running, - enable => true, + enable => true, hasstatus => true, - hasrestart => true, - subscribe => Class['nginx'], + hasrestart => true, + subscribe => Class['nginx'], } Exec['rebuild-nginx-vhosts'] ~> Service['nginx'] -} \ No newline at end of file +} From b9aac9292eed6919263aa082c5639f6e63a336ee Mon Sep 17 00:00:00 2001 From: James Fryman Date: Tue, 21 Jun 2011 12:03:47 -0700 Subject: [PATCH 08/13] added anchor pattern --- Modulefile | 2 ++ manifests/init.pp | 29 ++++++++++++++++++++--------- manifests/package.pp | 18 +++++++++++++++--- manifests/service.pp | 3 --- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/Modulefile b/Modulefile index 406078985..e5e98974b 100644 --- a/Modulefile +++ b/Modulefile @@ -6,3 +6,5 @@ license 'Apache License Version 2.0' summary 'Puppet NGINX management module' description 'This module can be used for basic NGINX Management' project_page 'http://github.com/puppetlabs/puppetlabs-nginx' + +dependency 'puppetlabs/stdlib', '>= 0.1.6' diff --git a/manifests/init.pp b/manifests/init.pp index ecfb9f0d8..8f2a51ad4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -10,7 +10,8 @@ # Actions: # # Requires: -# +# puppetlabs-stdlib - https://github.com/puppetlabs/puppetlabs-stdlib +# # Packaged NGINX # - RHEL: EPEL or custom package # - Debian/Ubuntu: Default Install or custom package @@ -24,16 +25,26 @@ # include nginx # } class nginx { + + class { 'stdlib': } - include nginx::package - include nginx::config - include nginx::service + anchor{ 'nginx::begin': + before => Class['nginx::package'], + notify => Class['nginx::service'], + } + + class { 'nginx::package': + notify => Class['nginx::service'], + } - Class['nginx::package'] -> Class['nginx::config'] ~> Class['nginx::service'] + class { 'nginx::config': + require => Class['nginx::package'], + notify => Class['nginx::service'], + } - # Allow the end user to establish relationships to the "main" class - # and preserve the relationship to the implementation classes through - # a transitive relationship to the composite class. - Class['nginx::service'] -> Class['nginx'] + class { 'nginx::service': } + anchor { 'nginx::end': + require => Class['nginx::service'], + } } diff --git a/manifests/package.pp b/manifests/package.pp index 5258c6f17..83ceae1c6 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -14,15 +14,27 @@ # # This class file is not called directly class nginx::package { + anchor { 'nginx::package::begin': } + anchor { 'nginx::package::end': } + case $operatingsystem { centos,fedora,rhel: { - include nginx::package::redhat + class { 'nginx::package::redhat': + require => Anchor['nginx::package::begin'], + before => Anchor['nginx::package::end'], + } } debian,ubuntu: { - include nginx::package::debian + class { 'nginx::package::debian': + require => Anchor['nginx::package::begin'], + before => Anchor['nginx::package::end'], + } } opensuse,suse: { - include nginx::package::suse + class { 'nginx::package::suse': + require => Anchor['nginx::package::begin'], + before => Anchor['nginx::package::end'], + } } } } diff --git a/manifests/service.pp b/manifests/service.pp index ee0f91f77..2ffc8e6f9 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -24,8 +24,5 @@ enable => true, hasstatus => true, hasrestart => true, - subscribe => Class['nginx'], } - - Exec['rebuild-nginx-vhosts'] ~> Service['nginx'] } From a6f98a88c2caf09392c2af35ce26385cb3eea737 Mon Sep 17 00:00:00 2001 From: James Fryman Date: Thu, 30 Jun 2011 12:37:12 -0500 Subject: [PATCH 09/13] Fixed README.markup --- README.markdown | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.markdown b/README.markdown index c47a27e62..b8f486eaa 100644 --- a/README.markdown +++ b/README.markdown @@ -8,12 +8,15 @@ This module manages NGINX from within Puppet. Install and bootstrap an NGINX instance +
     node default {
       class { 'nginx': }
     }
+
Setup a new virtual host +
     node default {
       class { 'mcollective': }
       nginx::resource::vhost { 'www.puppetlabs.com':
@@ -21,9 +24,11 @@ Setup a new virtual host
         www_root => '/var/www/www.puppetlabs.com',
       }
     }
+
Add a Proxy Server(s) +
    node default {
      class { 'mcollective': }
 	 nginx::resource::upstream { 'puppet_rack_app':
@@ -40,3 +45,4 @@ Add a Proxy Server(s)
        proxy  => 'http://puppet_rack_app',
      }
    } 
+
From f608b8ffd8bbd4b179ef7fed806fd754609c179c Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Wed, 15 Jun 2011 09:50:55 -0700 Subject: [PATCH 10/13] Contain all classes within Class[nginx] This change uses the anchor relationship from the puppetlabs-stdlib module to contain all of the module classes within the main "ntp" class. Without this change, end users of the module may have difficulty ordering things correctly since they will have to peek inside the module and figure out it's internal workings to identify all classes that require relationship edges. --- manifests/init.pp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 8f2a51ad4..1468860f4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -11,12 +11,16 @@ # # Requires: # puppetlabs-stdlib - https://github.com/puppetlabs/puppetlabs-stdlib -# +# # Packaged NGINX # - RHEL: EPEL or custom package # - Debian/Ubuntu: Default Install or custom package # - SuSE: Default Install or custom package # +# stdlib +# - puppetlabs-stdlib module >= 0.1.6 +# - plugin sync enabled to obtain the anchor type +# # Sample Usage: # # The module works with sensible defaults: @@ -25,15 +29,10 @@ # include nginx # } class nginx { - + class { 'stdlib': } - anchor{ 'nginx::begin': - before => Class['nginx::package'], - notify => Class['nginx::service'], - } - - class { 'nginx::package': + class { 'nginx::package': notify => Class['nginx::service'], } @@ -44,6 +43,13 @@ class { 'nginx::service': } + # Allow the end user to establish relationships to the "main" class + # and preserve the relationship to the implementation classes through + # a transitive relationship to the composite class. + anchor{ 'nginx::begin': + before => Class['nginx::package'], + notify => Class['nginx::service'], + } anchor { 'nginx::end': require => Class['nginx::service'], } From 1a3d758d4bee2386bbbe1e08c38d2ada3de8bf09 Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Wed, 15 Jun 2011 09:59:32 -0700 Subject: [PATCH 11/13] Update init.pp test with relationships This shows the module user how relationships can be easily added to the main nginx class without peeking inside the guts of the module. --- tests/init.pp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/init.pp b/tests/init.pp index 47b61b0ff..41cc19dec 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -1,2 +1,9 @@ -include nginx - +# The notify before should always come BEFORE all resources +# managed by the nginx class +# and the notify last should always come AFTER all resources +# managed by the nginx class. +node default { + notify { 'before': } + -> class { 'nginx': } + -> notify { 'last': } +} From c1166fde1afc89456d6283a15dad95f9ab551dcd Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Wed, 15 Jun 2011 10:16:30 -0700 Subject: [PATCH 12/13] Whitespace only cleanup of Class[nginx::service] --- manifests/service.pp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manifests/service.pp b/manifests/service.pp index 2ffc8e6f9..6d78a00a3 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -21,8 +21,9 @@ } service { "nginx": ensure => running, - enable => true, + enable => true, hasstatus => true, hasrestart => true, + subscribe => Exec['rebuild-nginx-vhosts'], } } From b8e25f29698fc1e6283a6db93f954706103f7bc9 Mon Sep 17 00:00:00 2001 From: Celso Fernandes Date: Sun, 29 Jan 2012 23:33:16 -0200 Subject: [PATCH 13/13] Changed module to use pupmod-concat (zertico's fork) instead of its own implementation of file fragment pattern - SSL option now is (present|absent) --- manifests/init.pp | 1 + manifests/resource/location.pp | 14 +++---- manifests/resource/vhost.pp | 72 ++++++++++++++++++---------------- manifests/service.pp | 6 --- tests/vhost.pp | 2 +- tests/vhost_ssl.erb | 2 +- 6 files changed, 48 insertions(+), 49 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 1468860f4..90fc278b9 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -11,6 +11,7 @@ # # Requires: # puppetlabs-stdlib - https://github.com/puppetlabs/puppetlabs-stdlib +# pupmod-concat - https://github.com/zertico/pupmod-concat # # Packaged NGINX # - RHEL: EPEL or custom package diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index 1e650b943..ebfea871f 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -30,7 +30,7 @@ $www_root = undef, $index_files = ['index.html', 'index.htm', 'index.php'], $proxy = undef, - $ssl = false, + $ssl = absent, $option = undef, $location ) { @@ -66,16 +66,14 @@ } ## Create stubs for vHost File Fragment Pattern - file {"${nginx::config::nx_temp_dir}/nginx.d/${vhost}-500-${name}": - ensure => $ensure_real, + concat_fragment { "${vhost}+500.tmp": content => $content_real, + ensure => $ensure, } ## Only create SSL Specific locations if $ssl is true. - if ($ssl == 'true') { - file {"${nginx::config::nx_temp_dir}/nginx.d/${vhost}-800-${name}-ssl": - ensure => $ensure_real, - content => $content_real, - } + concat_fragment { "${vhost}+800-ssl.tmp": + content => $content_real, + ensure => $ssl } } diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 41ba7427d..07f7e48ea 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -13,7 +13,7 @@ # [*index_files*] - Default index files for NGINX to read when traversing a directory # [*proxy*] - Proxy server(s) for a location to connect to. Accepts a single value, can be used in conjunction # with nginx::resource::upstream -# [*ssl*] - Indicates whether to setup SSL bindings for this location. +# [*ssl*] - Indicates whether to setup SSL bindings for this location. (present|absent) # [*ssl_cert*] - Pre-generated SSL Certificate file to reference for SSL Support. This is not generated by this module. # [*ssl_key*] - Pre-generated SSL Key file to reference for SSL Support. This is not generated by this module. # [*www_root*] - Specifies the location on disk for files to be read from. Cannot be set in conjunction with $proxy @@ -26,7 +26,7 @@ # nginx::resource::vhost { 'test2.local': # ensure => present, # www_root => '/var/www/nginx-default', -# ssl => 'true', +# ssl => present, # ssl_cert => '/tmp/server.crt', # ssl_key => '/tmp/server.pem', # } @@ -37,7 +37,7 @@ $ipv6_enable = false, $ipv6_listen_ip = '::', $ipv6_listen_port = '80', - $ssl = false, + $ssl = absent, $ssl_cert = undef, $ssl_key = undef, $proxy = undef, @@ -51,6 +51,30 @@ mode => '0644', } + file { "${nginx::params::nx_conf_dir}/sites-available/${name}": + ensure => $ensure ? { + 'absent' => absent, + default => 'file', + }, + } + + file { "${nginx::params::nx_conf_dir}/sites-enabled/${name}": + ensure => $ensure ? { + 'absent' => absent, + default => 'link', + }, + target => "${nginx::params::nx_conf_dir}/sites-available/${name}", + } + + concat_build { "${name}": + order => ['*.tmp'], + target => "${nginx::params::nx_conf_dir}/sites-available/${name}", + notify => Class['nginx::service'], + } + concat_fragment { "${name}+000.tmp": + content => "# !!File Managed By Puppet, Please Don't Touch This!!", + } + # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled # and support does not exist for it in the kernel. if ($ipv6_enable == 'true') and ($ipaddress6) { @@ -58,7 +82,7 @@ } # Check to see if SSL Certificates are properly defined. - if ($ssl == 'true') { + if ($ssl == present) { if ($ssl_cert == undef) or ($ssl_key == undef) { fail('nginx: SSL certificate/key (ssl_cert/ssl_cert) and/or SSL Private must be defined and exist on the target system(s)') } @@ -66,13 +90,9 @@ # Use the File Fragment Pattern to construct the configuration files. # Create the base configuration file reference. - file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-001": - ensure => $ensure ? { - 'absent' => absent, - default => 'file', - }, + concat_fragment { "${name}+001.tmp": content => template('nginx/vhost/vhost_header.erb'), - notify => Class['nginx::service'], + ensure => $ensure, } # Create the default location reference for the vHost @@ -87,32 +107,18 @@ } # Create a proper file close stub. - file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-699": - ensure => $ensure ? { - 'absent' => absent, - default => 'file', - }, + concat_fragment { "${name}+699.tmp": content => template('nginx/vhost/vhost_footer.erb'), - notify => Class['nginx::service'], + ensure => $ensure, } # Create SSL File Stubs if SSL is enabled - if ($ssl == 'true') { - file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-700-ssl": - ensure => $ensure ? { - 'absent' => absent, - default => 'file', - }, - content => template('nginx/vhost/vhost_ssl_header.erb'), - notify => Class['nginx::service'], - } - file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-999-ssl": - ensure => $ensure ? { - 'absent' => absent, - default => 'file', - }, - content => template('nginx/vhost/vhost_footer.erb'), - notify => Class['nginx::service'], - } + concat_fragment { "${name}+700-ssl.tmp": + content => template('nginx/vhost/vhost_ssl_header.erb'), + ensure => $ssl, + } + concat_fragment { "${name}+999-ssl.tmp": + content => template('nginx/vhost/vhost_footer.erb'), + ensure => $ssl, } } diff --git a/manifests/service.pp b/manifests/service.pp index 6d78a00a3..fb26eeb3d 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -14,16 +14,10 @@ # # This class file is not called directly class nginx::service { - exec { 'rebuild-nginx-vhosts': - command => "/bin/cat ${nginx::params::nx_temp_dir}/nginx.d/* > ${nginx::params::nx_conf_dir}/conf.d/vhost_autogen.conf", - refreshonly => true, - subscribe => File["${nginx::params::nx_temp_dir}/nginx.d"], - } service { "nginx": ensure => running, enable => true, hasstatus => true, hasrestart => true, - subscribe => Exec['rebuild-nginx-vhosts'], } } diff --git a/tests/vhost.pp b/tests/vhost.pp index 40658d937..6dd43afc3 100644 --- a/tests/vhost.pp +++ b/tests/vhost.pp @@ -1,4 +1,4 @@ -include nginix +include nginx nginx::resource::vhost { 'test.local': ensure => present, diff --git a/tests/vhost_ssl.erb b/tests/vhost_ssl.erb index 30e8bfbc1..a0e54e7c6 100644 --- a/tests/vhost_ssl.erb +++ b/tests/vhost_ssl.erb @@ -3,7 +3,7 @@ include nginx nginx::resource::vhost { 'test2.local': ensure => present, www_root => '/var/www/nginx-default', - ssl => 'true', + ssl => present, ssl_cert => '/tmp/server.crt', ssl_key => '/tmp/server.pem', }