From 5a34ea2f4ddb32ca251eea57af1817c69dc62c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Tue, 22 Oct 2013 03:23:00 -0300 Subject: [PATCH 1/2] Add test to prevent breaking the main conf --- spec/classes/nginx_spec.rb | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 09f5b5f..3280f7a 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -83,6 +83,52 @@ end describe 'Test customizations - template' do + let(:facts) { { :operatingsystem => 'Debian', :processorcount => 8 } } + let(:params) do + { + :template => "nginx/conf.d/nginx.conf.erb" + } + end + let(:expected) do +'# File Managed by Puppet +user www-data; +worker_processes 8; + +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; + # +} + +http { + server_tokens off; + include /etc/nginx/mime.types; + default_type application/octet-stream; + + access_log /var/log/nginx/access.log; + + sendfile on; + #tcp_nopush on; + tcp_nodelay on; + client_max_body_size 10m; + keepalive_timeout 65; + types_hash_max_size 1024; + + gzip on; + gzip_disable "MSIE [1-6]\.(?!.*SV1)"; + + include /etc/nginx/sites-available/*.conf; +} +' + end + it 'should generate a valid template' do + should contain_file('nginx.conf').with_content(expected) + end + end + + describe 'Test customizations - use own template' do let(:params) { {:template => "nginx/spec.erb" , :options => { 'opt_a' => 'value_a' } } } it 'should generate a valid template' do From ffcb5e2a9e7346e054542626fb8c3f80e91e3f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Tue, 22 Oct 2013 03:25:21 -0300 Subject: [PATCH 2/2] Add all of Debian's config dirs to the main config file Not adding them breaks upstreams configurations --- manifests/init.pp | 5 +++++ manifests/resource/location.pp | 5 +---- manifests/resource/upstream.pp | 2 +- manifests/resource/vhost.pp | 4 ++-- spec/classes/nginx_spec.rb | 3 +++ templates/conf.d/nginx.conf.erb | 3 +++ 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 3ad278c..2ad11f4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -293,6 +293,11 @@ } ### Calculation of variables that dependes on arguments + # Debian uses TWO configs dirs separatedly + $cdir = $::operatingsystem ? { + default => "${nginx::config_dir}/conf.d", + } + $vdir = $::operatingsystem ? { /(?i:Ubuntu|Debian|Mint)/ => "${nginx::config_dir}/sites-available", default => "${nginx::config_dir}/conf.d", diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index ae1c05e..26a50fa 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -77,10 +77,7 @@ default => file, } - $file_real = $::operatingsystem ? { - /(?i:Debian|Ubuntu|Mint)/ => "${nginx::config_dir}/sites-available/${vhost}.conf", - default => "${nginx::config_dir}/conf.d/${vhost}.conf", - } + $file_real = "${nginx::config_dir}/${nginx::vdir}/${vhost}.conf" # Use proxy template if $proxy is defined, otherwise use directory template. if ($proxy != undef) { diff --git a/manifests/resource/upstream.pp b/manifests/resource/upstream.pp index 64c0e0d..c16cf9a 100644 --- a/manifests/resource/upstream.pp +++ b/manifests/resource/upstream.pp @@ -35,7 +35,7 @@ default => file, } - file { "${nginx::config_dir}/conf.d/${name}-upstream.conf": + file { "${nginx::config_dir}/${nginx::cdir}/${name}-upstream.conf": ensure => $real_file, content => template($template_upstream), notify => $nginx::manage_service_autorestart, diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index ac87d35..40fa281 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -93,11 +93,12 @@ default => $groupowner, } + $file_real = "${nginx::config_dir}/${nginx::vdir}/${name}.conf" + # Some OS specific settings: # On Debian/Ubuntu manages sites-enabled case $::operatingsystem { ubuntu,debian,mint: { - $file_real = "${nginx::config_dir}/sites-available/${name}.conf" $manage_file = $ensure ? { present => link, @@ -112,7 +113,6 @@ } } redhat,centos,scientific,fedora: { - $file_real = "${nginx::config_dir}/conf.d/${name}.conf" # include nginx::redhat } default: { } diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 3280f7a..863f1d0 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -119,6 +119,9 @@ gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-available/*.conf; } ' diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index dd2335a..e5faba7 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -27,5 +27,8 @@ http { gzip <%= scope.lookupvar('nginx::real_gzip')%>; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; +<% if scope.lookupvar('nginx::cdir') != '' %> + include <%= scope.lookupvar('nginx::cdir')%>/*.conf; +<% end %> include <%= scope.lookupvar('nginx::vdir')%>/*.conf; }