Skip to content

Commit 2081493

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 8d3a95b commit 2081493

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
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::setenv
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@
577577
'mode' => '0600')
578578
}
579579
it { is_expected.to contain_class('apache::mod::alias') }
580+
it { is_expected.to contain_class('apache::mod::auth_basic') }
581+
it { is_expected.to contain_class('apache::mod::authn_file') }
582+
it { is_expected.to contain_class('apache::mod::authz_groupfile') }
583+
it { is_expected.to contain_class('apache::mod::auth_gssapi') }
580584
it { is_expected.to contain_class('apache::mod::env') }
581585
it { is_expected.to contain_class('apache::mod::fastcgi') }
582586
it { is_expected.to contain_class('apache::mod::filter') }
@@ -586,6 +590,7 @@
586590
it { is_expected.to contain_class('apache::mod::proxy') }
587591
it { is_expected.to contain_class('apache::mod::proxy_http') }
588592
it { is_expected.to contain_class('apache::mod::rewrite') }
593+
it { is_expected.to contain_class('apache::mod::setenv') }
589594
it { is_expected.to contain_class('apache::mod::setenvif') }
590595
it { is_expected.to contain_class('apache::mod::suexec') }
591596
it { is_expected.to contain_class('apache::mod::vhost_alias') }

0 commit comments

Comments
 (0)