Skip to content

Commit 06f04ad

Browse files
committed
(IAC-1186) Add $use_port_for_filenames parameter
When using $use_servername_for_filenames = true, virtual hosts with the same $servername but a different $port will introduce a duplicate resource declaration. Introduce a $use_port_for_filenames that act in concert with $use_servername_for_filenames to avoid this situation.
1 parent c1a830b commit 06f04ad

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

manifests/init.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@
837837
logroot_mode => $logroot_mode,
838838
manage_docroot => $default_vhost,
839839
use_servername_for_filenames => true,
840+
use_port_for_filenames => true,
840841
}
841842
$ssl_access_log_file = $::osfamily ? {
842843
'freebsd' => $access_log_file,
@@ -855,6 +856,7 @@
855856
logroot_mode => $logroot_mode,
856857
manage_docroot => $default_ssl_vhost,
857858
use_servername_for_filenames => true,
859+
use_port_for_filenames => true,
858860
}
859861
}
860862

manifests/vhost.pp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,13 @@
17291729
# When set to false (default), the existing behaviour of using the $name parameter
17301730
# will remain.
17311731
#
1732+
# @param $use_port_for_filenames
1733+
# When set to true and use_servername_for_filenames is also set to true, default log /
1734+
# config file names will be derived from the sanitized value of both the $servername and
1735+
# $port parameters.
1736+
# When set to false (default), the port is not included in the file names and may lead to
1737+
# duplicate declarations if two virtual hosts use the same domain.
1738+
#
17321739
# @param $mdomain
17331740
# All the names in the list are managed as one Managed Domain (MD). mod_md will request
17341741
# one single certificate that is valid for all these names.
@@ -1800,6 +1807,7 @@
18001807
$access_log_env_var = false,
18011808
Optional[Array] $access_logs = undef,
18021809
Optional[Boolean] $use_servername_for_filenames = false,
1810+
Optional[Boolean] $use_port_for_filenames = false,
18031811
$aliases = undef,
18041812
Optional[Variant[Hash, Array[Variant[Array,Hash]]]] $directories = undef,
18051813
Boolean $error_log = true,
@@ -2064,16 +2072,22 @@
20642072
# also perform some sanitiation on the $servername parameter to strip spaces from it, as it defaults to the value of
20652073
# $name, should $servername NOT be defined.
20662074
#
2075+
# Because a single hostname may be use by multiple virtual hosts listening on different ports, the $port paramter can
2076+
# optionaly be used to avoid duplicate resources.
2077+
#
20672078
# We will retain the default behaviour for filenames but allow the use of a sanitized version of $servername to be
2068-
# used, using the new $use_servername_for_filenames parameter.
2079+
# used, using the new $use_servername_for_filenames and $use_port_for_filenames parameters.
20692080
#
20702081
# This will default to false until the next major release (v6.0.0), at which point, we will default this to true and
20712082
# warn about it's imminent deprecation in the subsequent major release (v7.0.0)
20722083
#
2073-
# In v7.0.0, we will deprecate the $use_servername_for_filenames parameter altogether and use the sanitized value of
2074-
# $servername for default log / config filenames.
2084+
# In v7.0.0, we will deprecate the $use_servername_for_filenames and $use_port_for_filenames parameters altogether
2085+
# and use the sanitized value of $servername for default log / config filenames.
20752086
$filename = $use_servername_for_filenames ? {
2076-
true => regsubst($servername, ' ', '_', 'G'),
2087+
true => $use_port_for_filenames ? {
2088+
true => regsubst("${servername}-${port}", ' ', '_', 'G'),
2089+
false => regsubst($servername, ' ', '_', 'G'),
2090+
},
20772091
false => $name,
20782092
}
20792093

@@ -2088,6 +2102,17 @@
20882102
module, the $use_servername_for_filenames will be removed and log/config file names will be dervied from the
20892103
sanitized $servername parameter when not explicitly defined.'
20902104
warning($use_servername_for_filenames_warn_msg)
2105+
} elsif ! $use_port_for_filenames {
2106+
$use_port_for_filenames_warn_msg = '
2107+
It is possible for multiple virtual hosts to be configured using the same $servername but a different port. When
2108+
using $use_servername_for_filenames, this can lead to duplicate resource declarations.
2109+
When $use_port_for_filenames = true, the $servername and $port parameters, sanitized, are used to construct log and
2110+
config file names.
2111+
2112+
From version v6.0.0 of the puppetlabs-apache module, this parameter will default to true. From version v7.0.0 of the
2113+
module, the $use_port_for_filenames will be removed and log/config file names will be dervied from the
2114+
sanitized $servername parameter when not explicitly defined.'
2115+
warning($use_port_for_filenames_warn_msg)
20912116
}
20922117

20932118
# This ensures that the docroot exists

0 commit comments

Comments
 (0)