From f14fd057987b5489228a40444c3a101768c5b6bb Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 22 Feb 2011 22:59:40 +0100 Subject: first way to a unified partial based vhost template --- manifests/vhost.pp | 2 ++ manifests/vhost/php/standard.pp | 2 ++ manifests/vhost/template.pp | 6 +++++- templates/vhosts/default.erb | 16 ++++++++++++++++ templates/vhosts/partials/header_default.erb | 13 +++++++++++++ templates/vhosts/partials/logs.erb | 14 ++++++++++++++ 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 templates/vhosts/default.erb create mode 100644 templates/vhosts/partials/header_default.erb create mode 100644 templates/vhosts/partials/logs.erb diff --git a/manifests/vhost.pp b/manifests/vhost.pp index 6d9ae33..089eb62 100644 --- a/manifests/vhost.pp +++ b/manifests/vhost.pp @@ -40,6 +40,7 @@ define apache::vhost( $logpath = 'absent', $logmode = 'default', $template_mode = 'static', + $template_partial = 'absent', $vhost_mode = 'template', $vhost_source = 'absent', $vhost_destination = 'absent', @@ -95,6 +96,7 @@ define apache::vhost( path_is_webdir => $path_is_webdir, logpath => $logpath, logmode => $logmode, + template_partial => $template_partial, domain => $domain, domainalias => $domainalias, server_admin => $server_admin, diff --git a/manifests/vhost/php/standard.pp b/manifests/vhost/php/standard.pp index 9437046..61992a1 100644 --- a/manifests/vhost/php/standard.pp +++ b/manifests/vhost/php/standard.pp @@ -40,6 +40,7 @@ define apache::vhost::php::standard( $manage_webdir = true, $manage_docroot = true, $template_mode = 'php', + $template_partial = 'absent', $owner = root, $group = apache, $documentroot_owner = apache, @@ -152,6 +153,7 @@ define apache::vhost::php::standard( ensure => $ensure, path => $path, template_mode => $template_mode, + template_partial => $template_partial, vhost_mode => $vhost_mode, vhost_source => $vhost_source, vhost_destination => $vhost_destination, diff --git a/manifests/vhost/template.pp b/manifests/vhost/template.pp index b0c08f9..303de0e 100644 --- a/manifests/vhost/template.pp +++ b/manifests/vhost/template.pp @@ -75,6 +75,7 @@ define apache::vhost::template( $run_uid = 'absent', $run_gid = 'absent', $template_mode = 'static', + $template_partial = 'absent', $ssl_mode = false, $mod_security = true, $mod_security_relevantonly = true, @@ -174,7 +175,10 @@ define apache::vhost::template( } if $ensure != 'absent' { Apache::Vhost::File[$name]{ - content => template("apache/vhosts/$template_mode/$operatingsystem.erb") + content => $template_partial ? { + 'absent' => template("apache/vhosts/$template_mode/$operatingsystem.erb"), + default => template("apache/vhosts/default.erb"), + } } } } diff --git a/templates/vhosts/default.erb b/templates/vhosts/default.erb new file mode 100644 index 0000000..9e16337 --- /dev/null +++ b/templates/vhosts/default.erb @@ -0,0 +1,16 @@ +<%- [:normal,:ssl].each do |vhost_part| %> + + + <%= scope.function_template('apache/vhost/partials/header_default.erb') %> + <%= scope.function_template('apache/vhost/partials/logs.erb') %> + + <%- if ssl_mode == 'force' && vhost_part == :ssl %> + RewriteEngine On + RewriteCond %{HTTPS} !=on + RewriteRule (.*) https://%{SERVER_NAME}$1 [R=permanent,L] + <%- else %> + <%= scope.function_template(template_partial) %> + <%- end %> + + +<%- end %> diff --git a/templates/vhosts/partials/header_default.erb b/templates/vhosts/partials/header_default.erb new file mode 100644 index 0000000..13eeea1 --- /dev/null +++ b/templates/vhosts/partials/header_default.erb @@ -0,0 +1,13 @@ + Include include.d/defaults.inc + <%- if vhost_part == :ssl %> + Include include.d/ssl_defaults.inc + <%- end %> + + ServerName <%= servername %> + <%- unless serveralias.to_s.empty? then -%> + ServerAlias <%= serveralias %> + <%- end -%> + <%- unless server_admin.to_s.empty? or server_admin.to_s == 'absent' then -%> + ServerAdmin <%= server_admin %> + <%- end -%> + DocumentRoot <%= documentroot %>/ diff --git a/templates/vhosts/partials/logs.erb b/templates/vhosts/partials/logs.erb new file mode 100644 index 0000000..b61018c --- /dev/null +++ b/templates/vhosts/partials/logs.erb @@ -0,0 +1,14 @@ + <%- case logmode.to_s + when 'nologs' -%> + ErrorLog /dev/null + CustomLog /dev/null + <%- when 'semianonym' -%> + ErrorLog <%= logdir %>/error_log + CustomLog <%= logdir %>/access_log noip + <%- when 'anonym' -%> + ErrorLog /dev/null + CustomLog <%= logdir %>/access_log noip + <%- else -%> + ErrorLog <%= logdir %>/error_log + CustomLog <%= logdir %>/access_log combined + <%- end -%> -- cgit v1.2.3