Add $aliases and $redirect to apache::site, ensure default vhost is loaded first.

This commit is contained in:
Ossi Salmi 2010-02-18 13:32:34 +02:00 committed by Timo Mkinen
parent bf4ad72690
commit ced754f674
2 changed files with 41 additions and 21 deletions

View file

@ -94,51 +94,62 @@ class apache::server inherits apache::common {
# #
# $name: # $name:
# FQDN of virtual host. # FQDN of virtual host.
# $aliases:
# Optional ServerAlias for this virtual host.
# $root: # $root:
# Path to document root. Defaults to /srv/www/http/$fqdn # Path to document root. Defaults to /srv/www/http/$fqdn
# $config: # $config:
# Path to custom configuration file. Defaults to a basic template. # Path to custom configuration file. Defaults to a basic template.
# $redirect:
# Add redirect to given URL.
# #
# === Sample usage # === Sample usage
# #
# apache::site { "default":
# redirect => "http://www.example.com/",
# }
# apache::site { "www.example.com": # apache::site { "www.example.com":
# root => "/roles/prteam/public/public_access", # root => "/roles/prteam/public/public_access",
# config => "puppet:///path/to/www.example.com.conf", # config => "puppet:///path/to/www.example.com.conf",
# } # }
# #
define apache::site($root="", $config="") { define apache::site(aliases="", $root="", $config="", $redirect="") {
if $name == "default" { if $name == "default" {
$site_fqdn = $fqdn $site_fqdn = $fqdn
$site_conf = "/etc/httpd/site.http.d/00-${site_fqdn}.conf"
} else { } else {
$site_fqdn = $name $site_fqdn = $name
$site_conf = "/etc/httpd/site.http.d/10-${site_fqdn}.conf"
if $root { if !$redirect {
file { "/srv/www/http/${site_fqdn}": if $root {
ensure => link, file { "/srv/www/http/${site_fqdn}":
target => $root, ensure => link,
before => File["/etc/httpd/site.http.d/${site_fqdn}.conf"], 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, ensure => directory,
mode => 0755, mode => 0755,
owner => root, owner => root,
group => 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, ensure => present,
mode => 0644, mode => 0644,
owner => root, owner => root,
@ -147,11 +158,17 @@ define apache::site($root="", $config="") {
} }
if $config { if $config {
File["/etc/httpd/site.http.d/${site_fqdn}.conf"] { File["${site_conf}"] {
source => $config, source => $config,
} }
} else { }
File["/etc/httpd/site.http.d/${site_fqdn}.conf"] { if $redirect {
File["${site_conf}"] {
content => "<VirtualHost *:80>\n ServerName ${site_fqdn}\n Redirect permanent / ${redirect}\n</VirtualHost>\n",
}
}
if !$config and !$redirect {
File["${site_conf}"] {
content => template("apache/site.http.conf.erb"), content => template("apache/site.http.conf.erb"),
} }
} }

View file

@ -1,5 +1,8 @@
<VirtualHost *:80> <VirtualHost *:80>
ServerName <%= site_fqdn %> ServerName <%= site_fqdn %>
<% if aliases != "" -%>
ServerAlias <%= aliases %>
<% end -%>
ErrorLog /srv/www/log/http/<%= site_fqdn %>/error_log ErrorLog /srv/www/log/http/<%= site_fqdn %>/error_log
CustomLog /srv/www/log/http/<%= site_fqdn %>/access_log combined CustomLog /srv/www/log/http/<%= site_fqdn %>/access_log combined
DocumentRoot /srv/www/http/<%= site_fqdn %> DocumentRoot /srv/www/http/<%= site_fqdn %>