diff --git a/apache/manifests/init.pp b/apache/manifests/init.pp index c5965ab..ca82e31 100644 --- a/apache/manifests/init.pp +++ b/apache/manifests/init.pp @@ -94,51 +94,62 @@ class apache::server inherits apache::common { # # $name: # FQDN of virtual host. +# $aliases: +# Optional ServerAlias for this virtual host. # $root: # Path to document root. Defaults to /srv/www/http/$fqdn # $config: # Path to custom configuration file. Defaults to a basic template. +# $redirect: +# Add redirect to given URL. # # === Sample usage # +# apache::site { "default": +# redirect => "http://www.example.com/", +# } # apache::site { "www.example.com": # root => "/roles/prteam/public/public_access", # config => "puppet:///path/to/www.example.com.conf", # } # -define apache::site($root="", $config="") { +define apache::site(aliases="", $root="", $config="", $redirect="") { if $name == "default" { $site_fqdn = $fqdn + $site_conf = "/etc/httpd/site.http.d/00-${site_fqdn}.conf" } else { $site_fqdn = $name + $site_conf = "/etc/httpd/site.http.d/10-${site_fqdn}.conf" - if $root { - file { "/srv/www/http/${site_fqdn}": - ensure => link, - target => $root, - before => File["/etc/httpd/site.http.d/${site_fqdn}.conf"], + if !$redirect { + if $root { + file { "/srv/www/http/${site_fqdn}": + ensure => link, + target => $root, + before => File["${site_conf}"], + } + } else { + file { "/srv/www/http/${site_fqdn}": + ensure => directory, + mode => 0755, + owner => root, + group => root, + before => File["${site_conf}"], + } } - } else { - file { "/srv/www/http/${site_fqdn}": + + file { "/srv/www/log/http/${site_fqdn}": ensure => directory, mode => 0755, owner => root, group => root, - before => File["/etc/httpd/site.http.d/${site_fqdn}.conf"], + before => File["${site_conf}"], } } - - file { "/srv/www/log/http/${site_fqdn}": - ensure => directory, - mode => 0755, - owner => root, - group => root, - before => File["/etc/httpd/site.http.d/${site_fqdn}.conf"], - } } - file { "/etc/httpd/site.http.d/${site_fqdn}.conf": + file { "${site_conf}": ensure => present, mode => 0644, owner => root, @@ -147,11 +158,17 @@ define apache::site($root="", $config="") { } if $config { - File["/etc/httpd/site.http.d/${site_fqdn}.conf"] { + File["${site_conf}"] { source => $config, } - } else { - File["/etc/httpd/site.http.d/${site_fqdn}.conf"] { + } + if $redirect { + File["${site_conf}"] { + content => "\n ServerName ${site_fqdn}\n Redirect permanent / ${redirect}\n\n", + } + } + if !$config and !$redirect { + File["${site_conf}"] { content => template("apache/site.http.conf.erb"), } } diff --git a/apache/templates/site.http.conf.erb b/apache/templates/site.http.conf.erb index 1599c1d..f3945c8 100644 --- a/apache/templates/site.http.conf.erb +++ b/apache/templates/site.http.conf.erb @@ -1,5 +1,8 @@ ServerName <%= site_fqdn %> +<% if aliases != "" -%> + ServerAlias <%= aliases %> +<% end -%> ErrorLog /srv/www/log/http/<%= site_fqdn %>/error_log CustomLog /srv/www/log/http/<%= site_fqdn %>/access_log combined DocumentRoot /srv/www/http/<%= site_fqdn %>