Skip to content

Commit

Permalink
add $confd_only option and tests, add more tests to streamhost (see a…
Browse files Browse the repository at this point in the history
  • Loading branch information
William Yardley committed Oct 12, 2016
1 parent 6380151 commit f4cad4c
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 79 deletions.
78 changes: 34 additions & 44 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class nginx::config(
### START Module/App Configuration ###
$client_body_temp_path = $::nginx::params::client_body_temp_path,
$confd_only = false,
$confd_purge = false,
$conf_dir = $::nginx::params::conf_dir,
$daemon_user = $::nginx::params::daemon_user,
Expand Down Expand Up @@ -76,7 +77,6 @@
$keepalive_requests = '100',
$log_format = {},
$mail = false,
$stream = false,
$multi_accept = 'off',
$names_hash_bucket_size = '64',
$names_hash_max_size = '512',
Expand Down Expand Up @@ -139,6 +139,7 @@
if ($proxy_conf_template != undef) {
warning('The $proxy_conf_template parameter is deprecated and has no effect.')
}
validate_bool($confd_only)
validate_bool($confd_purge)
validate_bool($vhost_purge)
if ( $proxy_cache_path != false) {
Expand Down Expand Up @@ -227,21 +228,25 @@
file { "${conf_dir}/conf.stream.d":
ensure => directory,
}
if $confd_purge == true {
File["${conf_dir}/conf.stream.d"] {
purge => true,
recurse => true,
}
}

file { "${conf_dir}/conf.d":
ensure => directory,
}
if $confd_purge == true {
File["${conf_dir}/conf.d"] {
purge => true,
recurse => true,
notify => Class['::nginx::service'],
if $confd_purge {
# Err on the side of caution - make sure *both* $vhost_purge and
# $confd_purge are set if $confd_only is set, before purging files
# ${conf_dir}/conf.d
if (($confd_only and $vhost_purge) or !$confd_only) {
File["${conf_dir}/conf.d"] {
purge => true,
recurse => true,
notify => Class['::nginx::service'],
}
File["${conf_dir}/conf.stream.d"] {
purge => true,
recurse => true,
notify => Class['::nginx::service'],
}
}
}

Expand Down Expand Up @@ -273,25 +278,35 @@
owner => $daemon_user,
}

if $stream {
file { "${conf_dir}/streams-available":
unless $confd_only {
file { "${conf_dir}/sites-available":
ensure => directory,
owner => $sites_available_owner,
group => $sites_available_group,
mode => $sites_available_mode,
}

if $vhost_purge == true {
File["${conf_dir}/streams-available"] {
file { "${conf_dir}/sites-enabled":
ensure => directory,
}
if $vhost_purge {
File["${conf_dir}/sites-available"] {
purge => true,
recurse => true,
}
File["${conf_dir}/sites-enabled"] {
purge => true,
recurse => true,
}
}

file { "${conf_dir}/streams-enabled":
ensure => directory,
owner => $sites_available_owner,
group => $sites_available_group,
mode => $sites_available_mode,
}
file { "${conf_dir}/streams-available":
ensure => directory,
}

if $vhost_purge == true {
File["${conf_dir}/streams-enabled"] {
purge => true,
Expand All @@ -300,31 +315,6 @@
}
}

file { "${conf_dir}/sites-available":
ensure => directory,
owner => $sites_available_owner,
group => $sites_available_group,
mode => $sites_available_mode,
}

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

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

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

file { "${conf_dir}/nginx.conf":
ensure => file,
content => template($conf_template),
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
### END Nginx Configuration

### START Module/App Configuration ###
$confd_only = undef,
$confd_purge = undef,
$conf_dir = undef,
$daemon_user = undef,
Expand Down Expand Up @@ -234,6 +235,7 @@
client_body_temp_path => $client_body_temp_path,
client_max_body_size => $client_max_body_size,
confd_purge => $confd_purge,
confd_only => $confd_only,
conf_dir => $conf_dir,
conf_template => $conf_template,
daemon_user => $daemon_user,
Expand Down
8 changes: 7 additions & 1 deletion manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,13 @@
}

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

$config_file = "${vhost_dir}/${vhost_sanitized}.conf"

$location_sanitized_tmp = regsubst($location, '\/', '_', 'G')
$location_sanitized = regsubst($location_sanitized_tmp, '\\\\', '_', 'G')
Expand Down
38 changes: 22 additions & 16 deletions manifests/resource/streamhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@
"${mode} is not valid. It should be 4 digits (0644 by default).")

# Variables
$streamhost_dir = "${::nginx::config::conf_dir}/streams-available"
$streamhost_enable_dir = "${::nginx::config::conf_dir}/streams-enabled"
$streamhost_symlink_ensure = $ensure ? {
'absent' => absent,
default => 'link',
if $::nginx::config::confd_only {
$streamhost_dir = "${::nginx::config::conf_dir}/conf.stream.d"
} else {
$streamhost_dir = "${::nginx::config::conf_dir}/streams-available"
$streamhost_enable_dir = "${::nginx::config::conf_dir}/streams-enabled"
$streamhost_symlink_ensure = $ensure ? {
'absent' => absent,
default => 'link',
}
}

$name_sanitized = regsubst($name, ' ', '_', 'G')
Expand All @@ -134,10 +138,11 @@
}

concat { $config_file:
owner => $owner,
group => $group,
mode => $mode,
notify => Class['::nginx::service'],
owner => $owner,
group => $group,
mode => $mode,
notify => Class['::nginx::service'],
require => File[$streamhost_dir],
}

concat::fragment { "${name_sanitized}-header":
Expand All @@ -146,12 +151,13 @@
order => '001',
}

file{ "${name_sanitized}.conf symlink":
ensure => $streamhost_symlink_ensure,
path => "${streamhost_enable_dir}/${name_sanitized}.conf",
target => $config_file,
require => Concat[$config_file],
notify => Class['::nginx::service'],
unless $::nginx::config::confd_only {
file{ "${name_sanitized}.conf symlink":
ensure => $streamhost_symlink_ensure,
path => "${streamhost_enable_dir}/${name_sanitized}.conf",
target => $config_file,
require => [Concat[$config_file], File[$streamhost_enable_dir]],
notify => Class['::nginx::service'],
}
}

}
30 changes: 18 additions & 12 deletions manifests/resource/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,15 @@
"${mode} is not valid. It should be 4 digits (0644 by default).")

# Variables
$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',
if $::nginx::config::confd_only {
$vhost_dir = "${::nginx::config::conf_dir}/conf.d"
} else {
$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',
}
}

$name_sanitized = regsubst($name, ' ', '_', 'G')
Expand Down Expand Up @@ -597,7 +601,7 @@
group => $group,
mode => $mode,
notify => Class['::nginx::service'],
require => [File[$vhost_dir], File[$vhost_enable_dir]],
require => File[$vhost_dir],
}

$ssl_only = ($ssl == true) and (($ssl_port + 0) == ($listen_port + 0))
Expand Down Expand Up @@ -701,12 +705,14 @@
}
}

file{ "${name_sanitized}.conf symlink":
ensure => $vhost_symlink_ensure,
path => "${vhost_enable_dir}/${name_sanitized}.conf",
target => $config_file,
require => [File[$vhost_dir], File[$vhost_enable_dir], Concat[$config_file]],
notify => Class['::nginx::service'],
unless $::nginx::config::confd_only {
file{ "${name_sanitized}.conf symlink":
ensure => $vhost_symlink_ensure,
path => "${vhost_enable_dir}/${name_sanitized}.conf",
target => $config_file,
require => [File[$vhost_dir], File[$vhost_enable_dir], Concat[$config_file]],
notify => Class['::nginx::service'],
}
}

create_resources('::nginx::resource::map', $string_mappings)
Expand Down
Loading

0 comments on commit f4cad4c

Please sign in to comment.