From 8493febdc4a65737456ca9bc21f543bb51ec1a5e Mon Sep 17 00:00:00 2001 From: Justin Lambert Date: Mon, 4 Nov 2013 14:51:41 -0700 Subject: [PATCH] ensure default vhost config files are removed when false --- manifests/init.pp | 47 ++++++++++++++++++++++--------------- spec/classes/apache_spec.rb | 27 +++++++++++++++++++++ 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 3d7f368bab..560c0d9606 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -59,6 +59,7 @@ } validate_bool($default_vhost) + validate_bool($default_ssl_vhost) # true/false is sufficient for both ensure and enable validate_bool($service_enable) if $mpm_module { @@ -247,26 +248,34 @@ if $mpm_module { class { "apache::mod::${mpm_module}": } } - if $default_vhost { - apache::vhost { 'default': - port => 80, - docroot => $docroot, - scriptalias => $scriptalias, - serveradmin => $serveradmin, - access_log_file => $access_log_file, - priority => '15', - } + + $default_vhost_ensure = $default_vhost ? { + true => 'present', + false => 'absent' } - if $default_ssl_vhost { - apache::vhost { 'default-ssl': - port => 443, - ssl => true, - docroot => $docroot, - scriptalias => $scriptalias, - serveradmin => $serveradmin, - access_log_file => "ssl_${access_log_file}", - priority => '15', - } + $default_ssl_vhost_ensure = $default_ssl_vhost ? { + true => 'present', + false => 'absent' + } + + apache::vhost { 'default': + ensure => $default_vhost_ensure, + port => 80, + docroot => $docroot, + scriptalias => $scriptalias, + serveradmin => $serveradmin, + access_log_file => $access_log_file, + priority => '15', + } + apache::vhost { 'default-ssl': + ensure => $default_ssl_vhost_ensure, + port => 443, + ssl => true, + docroot => $docroot, + scriptalias => $scriptalias, + serveradmin => $serveradmin, + access_log_file => "ssl_${access_log_file}", + priority => '15', } } } diff --git a/spec/classes/apache_spec.rb b/spec/classes/apache_spec.rb index 51218cfd1b..1dd0ba1808 100644 --- a/spec/classes/apache_spec.rb +++ b/spec/classes/apache_spec.rb @@ -356,4 +356,31 @@ end end end + context 'on all OSes' do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + context 'default vhost defaults' do + it { should contain_apache__vhost('default').with_ensure('present') } + it { should contain_apache__vhost('default-ssl').with_ensure('absent') } + end + context 'without default non-ssl vhost' do + let :params do { + :default_vhost => false + } + end + it { should contain_apache__vhost('default').with_ensure('absent') } + end + context 'with default ssl vhost' do + let :params do { + :default_ssl_vhost => true + } + end + it { should contain_apache__vhost('default').with_ensure('present') } + end + end end