Skip to content

Instantly share code, notes, and snippets.

@rfdrake
Created August 24, 2015 15:25
Show Gist options
  • Save rfdrake/4f57fc9c1ca38a8b858f to your computer and use it in GitHub Desktop.
Save rfdrake/4f57fc9c1ca38a8b858f to your computer and use it in GitHub Desktop.
apache_vhost attempt at handling default values for apache::vhost
class apache_vhosts (
$vhosts = hiera('apache::vhosts', {}),
$options = [ "-Indexes", "+FollowSymLinks", "+MultiViews" ],
$override = [ "All" ],
)
{
# why all this trouble when create_resources supports default? Because we need to know the $name
validate_hash($vhosts)
each($vhosts) |$name, $value| {
if $value['__rewrite'] == true {
$merge = {
rewrites => [{
rewrite_cond => ['%{SERVER_PORT} =80'],
rewrite_rule => ['^(.*) https://%{SERVER_NAME}%{REQUEST_URI}'],
}],
docroot => '/var/www/',
port => 80,
servername => regsubst($name, '(.*?)_\d+$', '\1')
}
$new_values = delete($values, ['__rewrite'])
$vhash = { $name => $new_values }
#create_resources('::apache::vhost',$vhash,$merge)
} elsif $ssl == true or $port == '443' or $port == 443 {
$merge = {
options => $options,
override => $override,
ssl => true,
port => 443,
docroot => "/var/www/virtual/$name",
ssl_cert => "/etc/ssl/$name/server.crt",
ssl_key => "/var/www/$name/server.key",
servername => regsubst($name, '(.*?)_\d+$', '\1')
}
$vhash = { $name => $value }
create_resources('::apache::vhost',$vhash,$merge)
} else {
$merge = {
port => 80,
docroot => "/var/www/virtual/$name",
options => $options,
override => $override,
servername => regsubst($name, '(.*?)_\d+$', '\1')
}
$vhash = { $name => $value }
create_resources('::apache::vhost',$vhash,$merge)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment