Skip to content

Commit

Permalink
Merge pull request voxpupuli#1082 from ekohl/cleanups
Browse files Browse the repository at this point in the history
Clean up nginx::resource::server
  • Loading branch information
yastupin authored May 5, 2017
2 parents 21043c2 + 667da16 commit 7a47cae
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions manifests/resource/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,23 @@

# 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) {
if $ipv6_enable 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) {
if $ssl {
if $ssl_cert == undef {
fail('nginx: ssl_cert must be set to false or to a fully qualified path')
}
if ($ssl_key == undef) {
if $ssl_key == undef {
fail('nginx: ssl_key must be set to false or to a fully qualified path')
}
}

# Try to error in the case where the user sets ssl_port == listen_port but
# doesn't set ssl = true
if (!($ssl == true) and ($ssl_port == $listen_port)) {
if !$ssl and $ssl_port == $listen_port {
warning('nginx: ssl must be true if listen_port is the same as ssl_port')
}

Expand All @@ -311,25 +311,21 @@

# This deals with a situation where the listen directive for SSL doesn't match
# the port we want to force the SSL redirect to.
if ($ssl_redirect_port) {
if $ssl_redirect_port {
$_ssl_redirect_port = $ssl_redirect_port
} elsif ($ssl_port) {
} elsif $ssl_port {
$_ssl_redirect_port = $ssl_port
}

# Suppress unneeded stuff in non-SSL location block when certain conditions are
# met.
if (($ssl == true) and ($ssl_port == $listen_port)) or ($ssl_redirect) {
$ssl_only = true
} else {
$ssl_only = false
}
$ssl_only = ($ssl and $ssl_port == $listen_port) or $ssl_redirect

# If we're redirecting to SSL, the default location block is useless, *unless*
# SSL is enabled for this server
# either and ssl -> true
# ssl redirect and no ssl -> false
if ($ssl_redirect != true or $ssl == true) and $use_default_location == true {
if (!$ssl_redirect or $ssl) and $use_default_location {
# Create the default location reference for the server
nginx::resource::location {"${name_sanitized}-default":
ensure => $ensure,
Expand Down Expand Up @@ -401,16 +397,14 @@
}
}

if (($listen_port + 0) != ($ssl_port + 0)) {
if $listen_port != $ssl_port {
concat::fragment { "${name_sanitized}-header":
target => $config_file,
content => template('nginx/server/server_header.erb'),
order => '001',
}
}

# Create a proper file close stub.
if (($listen_port + 0) != ($ssl_port + 0)) {
# Create a proper file close stub.
concat::fragment { "${name_sanitized}-footer":
target => $config_file,
content => template('nginx/server/server_footer.erb'),
Expand All @@ -419,7 +413,7 @@
}

# Create SSL File Stubs if SSL is enabled
if ($ssl == true) {
if $ssl {
# Access and error logs are named differently in ssl template

concat::fragment { "${name_sanitized}-ssl-header":
Expand All @@ -439,7 +433,7 @@
ensure => $server_symlink_ensure,
path => "${server_enable_dir}/${name_sanitized}.conf",
target => $config_file,
require => [File[$server_dir], File[$server_enable_dir], Concat[$config_file]],
require => [File[$server_dir], Concat[$config_file]],
notify => Class['::nginx::service'],
}
}
Expand All @@ -448,7 +442,7 @@
create_resources('::nginx::resource::geo', $geo_mappings)
create_resources('::nginx::resource::location', $locations, {
ensure => $ensure,
server => $name_sanitized,
server => $name_sanitized,
ssl => $ssl,
ssl_only => $ssl_only,
www_root => $www_root,
Expand Down

0 comments on commit 7a47cae

Please sign in to comment.