Skip to content

Commit

Permalink
Merge pull request #338 from janorn/config_dir
Browse files Browse the repository at this point in the history
Add nginx config dir as a parameter
  • Loading branch information
James Fryman committed Jun 16, 2014
2 parents 026c2de + 1bfd597 commit 144b653
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 42 deletions.
33 changes: 17 additions & 16 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
$client_body_buffer_size = $nginx::params::nx_client_body_buffer_size,
$client_max_body_size = $nginx::params::nx_client_max_body_size,
$confd_purge = $nginx::params::nx_confd_purge,
$conf_dir = $nginx::params::nx_conf_dir,
$conf_template = $nginx::params::nx_conf_template,
$daemon_user = $nginx::params::nx_daemon_user,
$events_use = $nginx::params::nx_events_use,
Expand Down Expand Up @@ -65,35 +66,35 @@
mode => '0644',
}

file { $nginx::params::nx_conf_dir:
file { $conf_dir:
ensure => directory,
}

file { "${nginx::params::nx_conf_dir}/conf.d":
file { "${conf_dir}/conf.d":
ensure => directory,
}
if $confd_purge == true {
File["${nginx::params::nx_conf_dir}/conf.d"] {
File["${conf_dir}/conf.d"] {
purge => true,
recurse => true,
}
}

file { "${nginx::params::nx_conf_dir}/conf.mail.d":
file { "${conf_dir}/conf.mail.d":
ensure => directory,
}
if $confd_purge == true {
File["${nginx::params::nx_conf_dir}/conf.mail.d"] {
File["${conf_dir}/conf.mail.d"] {
purge => true,
recurse => true,
}
}

file { "${nginx::params::nx_conf_dir}/conf.d/vhost_autogen.conf":
file { "${conf_dir}/conf.d/vhost_autogen.conf":
ensure => absent,
}

file { "${nginx::params::nx_conf_dir}/conf.mail.d/vhost_autogen.conf":
file { "${conf_dir}/conf.mail.d/vhost_autogen.conf":
ensure => absent,
}

Expand All @@ -111,47 +112,47 @@
owner => $daemon_user,
}

file { "${nginx::params::nx_conf_dir}/sites-available":
file { "${conf_dir}/sites-available":
ensure => directory,
}

if $vhost_purge == true {
File["${nginx::params::nx_conf_dir}/sites-available"] {
File["${conf_dir}/sites-available"] {
purge => true,
recurse => true,
}
}

file { "${nginx::params::nx_conf_dir}/sites-enabled":
file { "${conf_dir}/sites-enabled":
ensure => directory,
}

if $vhost_purge == true {
File["${nginx::params::nx_conf_dir}/sites-enabled"] {
File["${conf_dir}/sites-enabled"] {
purge => true,
recurse => true,
}
}

file { '/etc/nginx/sites-enabled/default':
file { "${conf_dir}/sites-enabled/default":
ensure => absent,
}

file { "${nginx::params::nx_conf_dir}/nginx.conf":
file { "${conf_dir}/nginx.conf":
ensure => file,
content => template($conf_template),
}

file { "${nginx::params::nx_conf_dir}/conf.d/proxy.conf":
file { "${conf_dir}/conf.d/proxy.conf":
ensure => file,
content => template($proxy_conf_template),
}

file { "${nginx::params::nx_conf_dir}/conf.d/default.conf":
file { "${conf_dir}/conf.d/default.conf":
ensure => absent,
}

file { "${nginx::params::nx_conf_dir}/conf.d/example_ssl.conf":
file { "${conf_dir}/conf.d/example_ssl.conf":
ensure => absent,
}

Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
$client_max_body_size = $nginx::params::nx_client_max_body_size,
$confd_purge = $nginx::params::nx_confd_purge,
$configtest_enable = $nginx::params::nx_configtest_enable,
$conf_dir = $nginx::params::nx_conf_dir,
$conf_template = $nginx::params::nx_conf_template,
$daemon_user = $nginx::params::nx_daemon_user,
$events_use = $nginx::params::nx_events_use,
Expand Down Expand Up @@ -170,6 +171,7 @@
client_body_buffer_size => $client_body_buffer_size,
client_max_body_size => $client_max_body_size,
confd_purge => $confd_purge,
conf_dir => $conf_dir,
conf_template => $conf_template,
daemon_user => $daemon_user,
events_use => $events_use,
Expand Down
10 changes: 5 additions & 5 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
$proxy_connect_timeout = $nginx::config::proxy_connect_timeout,
$proxy_set_header = $nginx::config::proxy_set_header,
$fastcgi = undef,
$fastcgi_params = '/etc/nginx/fastcgi_params',
$fastcgi_params = "${nginx::config::conf_dir}/fastcgi_params",
$fastcgi_script = undef,
$fastcgi_split_path = undef,
$ssl = false,
Expand Down Expand Up @@ -240,7 +240,7 @@
}

$vhost_sanitized = regsubst($vhost, ' ', '_', 'G')
$config_file = "${nginx::config::nx_conf_dir}/sites-available/${vhost_sanitized}.conf"
$config_file = "${nginx::config::conf_dir}/sites-available/${vhost_sanitized}.conf"

$location_sanitized_tmp = regsubst($location, '\/', '_', 'G')
$location_sanitized = regsubst($location_sanitized_tmp, "\\\\", '_', 'G')
Expand Down Expand Up @@ -271,8 +271,8 @@
$content_real = template('nginx/vhost/vhost_location_empty.erb')
}

if $fastcgi != undef and !defined(File['/etc/nginx/fastcgi_params']) {
file { '/etc/nginx/fastcgi_params':
if $fastcgi != undef and !defined(File[$fastcgi_params]) {
file { $fastcgi_params:
ensure => present,
mode => '0770',
content => template('nginx/vhost/fastcgi_params.erb'),
Expand Down Expand Up @@ -306,7 +306,7 @@

if ($auth_basic_user_file != undef) {
#Generate htpasswd with provided file-locations
file { "${nginx::params::nx_conf_dir}/${location_sanitized}_htpasswd":
file { "${nginx::config::conf_dir}/${location_sanitized}_htpasswd":
ensure => $ensure,
mode => '0644',
source => $auth_basic_user_file,
Expand Down
2 changes: 1 addition & 1 deletion manifests/resource/mailhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
validate_string($xclient)
validate_array($server_name)

$config_file = "${nginx::config::nx_conf_dir}/conf.mail.d/${name}.conf"
$config_file = "${nginx::config::conf_dir}/conf.mail.d/${name}.conf"

# Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
# and support does not exist for it in the kernel.
Expand Down
2 changes: 1 addition & 1 deletion manifests/resource/upstream.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
mode => '0644',
}

file { "/etc/nginx/conf.d/${name}-upstream.conf":
file { "${nginx::config::conf_dir}/conf.d/${name}-upstream.conf":
ensure => $ensure ? {
'absent' => absent,
default => 'file',
Expand Down
20 changes: 10 additions & 10 deletions manifests/resource/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
$proxy_set_body = undef,
$resolver = [],
$fastcgi = undef,
$fastcgi_params = '/etc/nginx/fastcgi_params',
$fastcgi_params = "${nginx::config::conf_dir}/fastcgi_params",
$fastcgi_script = undef,
$index_files = [
'index.html',
Expand Down Expand Up @@ -334,8 +334,8 @@
validate_array($rewrite_rules)

# Variables
$vhost_dir = "${nginx::config::nx_conf_dir}/sites-available"
$vhost_enable_dir = "${nginx::config::nx_conf_dir}/sites-enabled"
$vhost_dir = "${nginx::config::conf_dir}/sites-available"
$vhost_enable_dir = "${nginx::config::conf_dir}/sites-enabled"
$vhost_symlink_ensure = $ensure ? {
'absent' => absent,
default => 'link',
Expand Down Expand Up @@ -450,8 +450,8 @@
location_custom_cfg_append => $location_custom_cfg_append }
}

if $fastcgi != undef and !defined(File['/etc/nginx/fastcgi_params']) {
file { '/etc/nginx/fastcgi_params':
if $fastcgi != undef and !defined(File[$fastcgi_params]) {
file { $fastcgi_params:
ensure => present,
mode => '0770',
content => template('nginx/vhost/fastcgi_params.erb'),
Expand Down Expand Up @@ -515,32 +515,32 @@

# Check if the file has been defined before creating the file to
# avoid the error when using wildcard cert on the multiple vhosts
ensure_resource('file', "${nginx::params::nx_conf_dir}/${cert}.crt", {
ensure_resource('file', "${nginx::config::conf_dir}/${cert}.crt", {
owner => $nginx::config::daemon_user,
mode => '0444',
source => $ssl_cert,
})
ensure_resource('file', "${nginx::params::nx_conf_dir}/${cert}.key", {
ensure_resource('file', "${nginx::config::conf_dir}/${cert}.key", {
owner => $nginx::config::daemon_user,
mode => '0440',
source => $ssl_key,
})
if ($ssl_dhparam != undef) {
ensure_resource('file', "${nginx::params::nx_conf_dir}/${cert}.dh.pem", {
ensure_resource('file', "${nginx::config::conf_dir}/${cert}.dh.pem", {
owner => $nginx::config::daemon_user,
mode => '0440',
source => $ssl_dhparam,
})
}
if ($ssl_stapling_file != undef) {
ensure_resource('file', "${nginx::params::nx_conf_dir}/${cert}.ocsp.resp", {
ensure_resource('file', "${nginx::config::conf_dir}/${cert}.ocsp.resp", {
owner => $nginx::config::daemon_user,
mode => '0440',
source => $ssl_stapling_file,
})
}
if ($ssl_trusted_cert != undef) {
ensure_resource('file', "${nginx::params::nx_conf_dir}/${cert}.trusted.crt", {
ensure_resource('file', "${nginx::config::conf_dir}/${cert}.trusted.crt", {
owner => $nginx::config::daemon_user,
mode => '0440',
source => $ssl_trusted_cert,
Expand Down
12 changes: 12 additions & 0 deletions spec/defines/resource_upstream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
:members => ['test'],
}
end
let :facts do
{
:osfamily => 'Debian',
:operatingsystem => 'debian',
}
end
let :pre_condition do
[
'include ::nginx::params',
'include ::nginx::config',
]
end

describe 'os-independent items' do

Expand Down
8 changes: 4 additions & 4 deletions templates/conf.d/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ events {
}

http {
include <%= scope.lookupvar('nginx::params::nx_conf_dir') %>/mime.types;
include <%= @conf_dir %>/mime.types;
default_type application/octet-stream;

access_log <%= @http_access_log %>;
Expand Down Expand Up @@ -60,12 +60,12 @@ http {
<% end -%>
<% end -%>

include <%= scope.lookupvar('nginx::params::nx_conf_dir') %>/conf.d/*.conf;
include <%= scope.lookupvar('nginx::params::nx_conf_dir') %>/sites-enabled/*;
include <%= @conf_dir %>/conf.d/*.conf;
include <%= @conf_dir %>/sites-enabled/*;

}
<% if scope.lookupvar('nginx::mail') %>
mail {
include <%= scope.lookupvar('nginx::params::nx_conf_dir') %>/conf.mail.d/*.conf;
include <%= @conf_dir %>/conf.mail.d/*.conf;
}
<% end -%>
10 changes: 5 additions & 5 deletions templates/vhost/vhost_ssl_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ server {

ssl on;

ssl_certificate <%= scope.lookupvar('nginx::params::nx_conf_dir') %>/<%= @name.gsub(' ', '_') %>.crt;
ssl_certificate_key <%= scope.lookupvar('nginx::params::nx_conf_dir') %>/<%= @name.gsub(' ', '_') %>.key;
ssl_certificate <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.crt;
ssl_certificate_key <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.key;
<% if defined? @ssl_dhparam -%>
ssl_dhparam <%= scope.lookupvar('nginx::params::nx_conf_dir') %>/<%= @name.gsub(' ', '_') %>.dh.pem;
ssl_dhparam <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.dh.pem;
<% end -%>
ssl_session_cache <%= @ssl_cache %>;
ssl_session_timeout 5m;
Expand All @@ -21,7 +21,7 @@ server {
ssl_stapling on;
<% end -%>
<% if defined? @ssl_stapling_file -%>
ssl_stapling_file <%= scope.lookupvar('nginx::params::nx_conf_dir') %>/<%= @name.gsub(' ', '_') %>.ocsp.resp;
ssl_stapling_file <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.ocsp.resp;
<% end -%>
<% if defined? @ssl_stapling_responder -%>
ssl_stapling_responder <%= @ssl_stapling_responder %>;
Expand All @@ -30,7 +30,7 @@ server {
ssl_stapling_verify on;
<% end -%>
<% if defined? @ssl_trusted_cert -%>
ssl_trusted_certificate <%= scope.lookupvar('nginx::params::nx_conf_dir') %>/<%= @name.gsub(' ', '_') %>.trusted.crt;
ssl_trusted_certificate <%= scope.lookupvar('nginx::config::conf_dir') %>/<%= @name.gsub(' ', '_') %>.trusted.crt;
<% end -%>
<% if @resolver.count > 0 -%>
resolver <% Array(@resolver).each do |r| %> <%= r %><% end %>;
Expand Down

0 comments on commit 144b653

Please sign in to comment.