Skip to content

Commit 3241a6d

Browse files
committed
Automatically include modules used in vhost directories
The data passed to the directories parameter of apache::vhost often implies a module should be present. This change inspects the passed data and automatically includes modules if needed. This makes it easier to use via Hiera while disabling all default mods. Because of this change one acceptance test becomes obsolete: it no longer fails and just works.
1 parent de70a47 commit 3241a6d

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed

manifests/vhost.pp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,40 @@
23662366
# - $suphp_engine
23672367
# - $shibboleth_enabled
23682368
if $_directories and ! empty($_directories) and $ensure == 'present' {
2369+
$_directories.each |Hash $directory| {
2370+
if 'auth_basic_authoritative' in $directory or 'auth_basic_fake' in $directory or 'auth_basic_provider' in $directory {
2371+
include apache::mod::auth_basic
2372+
}
2373+
2374+
if 'auth_user_file' in $directory {
2375+
include apache::mod::authn_file
2376+
}
2377+
2378+
if 'auth_group_file' in $directory {
2379+
include apache::mod::authz_groupfile
2380+
}
2381+
2382+
if 'gssapi' in $directory {
2383+
include apache::mod::auth_gssapi
2384+
}
2385+
2386+
if $directory['provider'] and $directory['provider'] =~ 'location' and ('proxy_pass' in $directory or 'proxy_pass_match' in $directory) {
2387+
include apache::mod::proxy_http
2388+
}
2389+
2390+
if 'request_headers' in $directory {
2391+
include apache::mod::headers
2392+
}
2393+
2394+
if 'rewrites' in $directory {
2395+
include apache::mod::rewrite
2396+
}
2397+
2398+
if 'setenv' in $directory {
2399+
include apache::mod::env
2400+
}
2401+
}
2402+
23692403
concat::fragment { "${name}-directories":
23702404
target => "${priority_real}${filename}.conf",
23712405
order => 60,

spec/acceptance/default_mods_spec.rb

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,6 @@ class { 'apache':
2222
end
2323
end
2424

25-
unless os[:family] == 'sles' && os[:release].to_i >= 12
26-
describe 'no default mods and failing' do
27-
before :all do
28-
pp = <<-PP
29-
include apache::params
30-
class { 'apache': default_mods => false, service_ensure => stopped, }
31-
PP
32-
apply_manifest(pp)
33-
end
34-
# Using puppet_apply as a helper
35-
pp = <<-MANIFEST
36-
class { 'apache':
37-
default_mods => false,
38-
}
39-
apache::vhost { 'defaults.example.com':
40-
docroot => '#{apache_hash['doc_root']}/defaults',
41-
aliases => [
42-
{
43-
alias => '/css',
44-
path => '#{apache_hash['doc_root']}/css',
45-
},
46-
],
47-
directories => [
48-
{
49-
'path' => "#{apache_hash['doc_root']}/admin",
50-
'auth_basic_fake' => 'demo demopass',
51-
}
52-
],
53-
setenv => 'TEST1 one',
54-
}
55-
MANIFEST
56-
it 'applies with errors' do
57-
apply_manifest(pp, expect_failures: true)
58-
end
59-
end
60-
61-
describe service(apache_hash['service_name']) do
62-
it { is_expected.not_to be_running }
63-
end
64-
end
65-
6625
describe 'alternative default mods' do
6726
# Using puppet_apply as a helper
6827
let(:pp) do

spec/defines/vhost_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@
194194
'path' => '/',
195195
'provider' => 'location',
196196
'auth_ldap_referrals' => 'off',
197+
'auth_basic_fake' => 'demo demopass',
198+
'auth_user_file' => '/path/to/authz_user_file',
199+
'auth_group_file' => '/path/to/authz_group_file',
200+
'setenv' => ['SPECIAL_PATH /foo/bin'],
197201
},
198202
{
199203
'path' => '/proxy',
@@ -568,6 +572,10 @@
568572
'mode' => '0600')
569573
}
570574
it { is_expected.to contain_class('apache::mod::alias') }
575+
it { is_expected.to contain_class('apache::mod::auth_basic') }
576+
it { is_expected.to contain_class('apache::mod::authn_file') }
577+
it { is_expected.to contain_class('apache::mod::authz_groupfile') }
578+
it { is_expected.to contain_class('apache::mod::auth_gssapi') }
571579
it { is_expected.to contain_class('apache::mod::env') }
572580
it { is_expected.to contain_class('apache::mod::filter') }
573581
it { is_expected.to contain_class('apache::mod::headers') }
@@ -1289,7 +1297,7 @@
12891297
it { is_expected.not_to contain_concat__fragment('rspec.example.com-aliases') }
12901298
it { is_expected.not_to contain_concat__fragment('rspec.example.com-itk') }
12911299
it { is_expected.not_to contain_concat__fragment('rspec.example.com-fallbackresource') }
1292-
it { is_expected.to contain_concat__fragment('rspec.example.com-directories') }
1300+
it { is_expected.not_to contain_concat__fragment('rspec.example.com-directories') }
12931301
it { is_expected.not_to contain_concat__fragment('rspec.example.com-additional_includes') }
12941302
it { is_expected.to contain_concat__fragment('rspec.example.com-logging') }
12951303
it { is_expected.to contain_concat__fragment('rspec.example.com-serversignature') }

0 commit comments

Comments
 (0)