Skip to content

Commit f1ad00d

Browse files
author
sanfrancrisko
authored
Merge pull request #2122 from smortex/use_port_for_filenames
(IAC-1186) Add $use_port_for_filenames parameter
2 parents c1a830b + fb2a84f commit f1ad00d

File tree

7 files changed

+52
-20
lines changed

7 files changed

+52
-20
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

manifests/vhost/fragment.pp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#
5656
define apache::vhost::fragment (
5757
String[1] $vhost,
58+
Optional[Integer[0]] $port = undef,
5859
$priority = undef,
5960
Optional[String] $content = undef,
6061
Integer[0] $order = 900,
@@ -68,7 +69,10 @@
6869
$priority_real = '25-'
6970
}
7071

71-
$filename = regsubst($vhost, ' ', '_', 'G')
72+
$filename = $port ? {
73+
Integer => regsubst("${vhost}-${port}", ' ', '_', 'G'),
74+
Undef => regsubst($vhost, ' ', '_', 'G'),
75+
}
7276

7377
if $content =~ String[1] {
7478
concat::fragment { "${vhost}-${title}":

spec/acceptance/apache_ssl_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class { 'apache':
3030
end
3131
end
3232

33-
describe file("#{apache_hash['vhost_dir']}/15-default-ssl.conf") do
33+
describe file("#{apache_hash['vhost_dir']}/15-default-ssl-443.conf") do
3434
it { is_expected.to be_file }
3535
it { is_expected.to contain 'SSLCertificateFile "/tmp/ssl_cert"' }
3636
it { is_expected.to contain 'SSLCertificateKeyFile "/tmp/ssl_key"' }

spec/acceptance/vhost_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class { 'apache':
2525
apply_manifest(pp, catch_failures: true)
2626
end
2727

28-
describe file("#{apache_hash['vhost_dir']}/15-default.conf") do
28+
describe file("#{apache_hash['vhost_dir']}/15-default-80.conf") do
2929
it { is_expected.not_to be_file }
3030
end
3131

32-
describe file("#{apache_hash['vhost_dir']}/15-default-ssl.conf") do
32+
describe file("#{apache_hash['vhost_dir']}/15-default-ssl-443.conf") do
3333
it { is_expected.not_to be_file }
3434
end
3535
end
@@ -42,11 +42,11 @@ class { 'apache': }
4242
apply_manifest(pp, catch_failures: true)
4343
end
4444

45-
describe file("#{apache_hash['vhost_dir']}/15-default.conf") do
45+
describe file("#{apache_hash['vhost_dir']}/15-default-80.conf") do
4646
it { is_expected.to contain '<VirtualHost \*:80>' }
4747
end
4848

49-
describe file("#{apache_hash['vhost_dir']}/15-default-ssl.conf") do
49+
describe file("#{apache_hash['vhost_dir']}/15-default-ssl-443.conf") do
5050
it { is_expected.not_to be_file }
5151
end
5252
end
@@ -67,11 +67,11 @@ class { 'apache':
6767
apply_manifest(pp, catch_failures: true)
6868
end
6969

70-
describe file("#{apache_hash['vhost_dir']}/15-default.conf") do
70+
describe file("#{apache_hash['vhost_dir']}/15-default-80.conf") do
7171
it { is_expected.to contain '<VirtualHost \*:80>' }
7272
end
7373

74-
describe file("#{apache_hash['vhost_dir']}/15-default-ssl.conf") do
74+
describe file("#{apache_hash['vhost_dir']}/15-default-ssl-443.conf") do
7575
it { is_expected.to contain '<VirtualHost \*:443>' }
7676
it { is_expected.to contain 'SSLEngine on' }
7777
end

spec/defines/vhost_fragment_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
let(:params) do
1515
{
1616
vhost: 'default',
17+
port: 80,
1718
priority: '15',
1819
}
1920
end
@@ -23,9 +24,9 @@
2324

2425
it 'creates a vhost concat fragment' do
2526
is_expected.to compile.with_all_deps
26-
is_expected.to contain_concat('15-default.conf')
27+
is_expected.to contain_concat('15-default-80.conf')
2728
is_expected.to create_concat__fragment('default-myfragment')
28-
.with_target('15-default.conf')
29+
.with_target('15-default-80.conf')
2930
.with_order(900)
3031
.with_content('# Foo')
3132
end
@@ -36,7 +37,7 @@
3637

3738
it 'does not create a vhost concat fragment' do
3839
is_expected.to compile.with_all_deps
39-
is_expected.to contain_concat('15-default.conf')
40+
is_expected.to contain_concat('15-default-80.conf')
4041
is_expected.not_to contain_concat__fragment('default-myfragment')
4142
end
4243
end

spec/spec_helper_acceptance_local.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def apache_settings_hash
8989
apache['conf_file'] = '/etc/httpd/conf/httpd.conf'
9090
apache['ports_file'] = '/etc/httpd/conf/ports.conf'
9191
apache['vhost_dir'] = '/etc/httpd/conf.d'
92-
apache['vhost'] = '/etc/httpd/conf.d/15-default.conf'
92+
apache['vhost'] = '/etc/httpd/conf.d/15-default-80.conf'
9393
apache['run_dir'] = '/var/run/httpd'
9494
apache['doc_root'] = '/var/www'
9595
apache['service_name'] = 'httpd'
@@ -119,7 +119,7 @@ def apache_settings_hash
119119
apache['mod_dir'] = '/etc/apache2/mods-available'
120120
apache['conf_file'] = '/etc/apache2/apache2.conf'
121121
apache['ports_file'] = '/etc/apache2/ports.conf'
122-
apache['vhost'] = '/etc/apache2/sites-available/15-default.conf'
122+
apache['vhost'] = '/etc/apache2/sites-available/15-default-80.conf'
123123
apache['vhost_dir'] = '/etc/apache2/sites-enabled'
124124
apache['run_dir'] = '/var/run/apache2'
125125
apache['doc_root'] = '/var/www'
@@ -141,7 +141,7 @@ def apache_settings_hash
141141
apache['mod_dir'] = '/usr/local/etc/apache24/Modules'
142142
apache['conf_file'] = '/usr/local/etc/apache24/httpd.conf'
143143
apache['ports_file'] = '/usr/local/etc/apache24/Includes/ports.conf'
144-
apache['vhost'] = '/usr/local/etc/apache24/Vhosts/15-default.conf'
144+
apache['vhost'] = '/usr/local/etc/apache24/Vhosts/15-default-80.conf'
145145
apache['vhost_dir'] = '/usr/local/etc/apache24/Vhosts'
146146
apache['run_dir'] = '/var/run/apache24'
147147
apache['doc_root'] = '/var/www'
@@ -155,7 +155,7 @@ def apache_settings_hash
155155
apache['mod_dir'] = '/etc/apache2/modules.d'
156156
apache['conf_file'] = '/etc/apache2/httpd.conf'
157157
apache['ports_file'] = '/etc/apache2/ports.conf'
158-
apache['vhost'] = '/etc/apache2/vhosts.d/15-default.conf'
158+
apache['vhost'] = '/etc/apache2/vhosts.d/15-default-80.conf'
159159
apache['vhost_dir'] = '/etc/apache2/vhosts.d'
160160
apache['run_dir'] = '/var/run/apache2'
161161
apache['doc_root'] = '/var/www'
@@ -169,7 +169,7 @@ def apache_settings_hash
169169
apache['mod_dir'] = '/etc/apache2/mods-available'
170170
apache['conf_file'] = '/etc/apache2/httpd.conf'
171171
apache['ports_file'] = '/etc/apache2/ports.conf'
172-
apache['vhost'] = '/etc/apache2/sites-available/15-default.conf'
172+
apache['vhost'] = '/etc/apache2/sites-available/15-default-80.conf'
173173
apache['vhost_dir'] = '/etc/apache2/sites-available'
174174
apache['run_dir'] = '/var/run/apache2'
175175
apache['doc_root'] = '/srv/www'

0 commit comments

Comments
 (0)