puppet/apache/manifests/debian.pp
2010-11-05 22:56:18 +02:00

243 lines
5.9 KiB
Puppet

class apache::debian::common {
if ! $httpd_user {
$httpd_user = "www-data"
}
if ! $httpd_group {
$httpd_group = "www-data"
}
file { [ "/srv/www/http",
"/srv/www/http/${fqdn}",
"/srv/www/log/http",
"/srv/www/log/http/${fqdn}", ]:
ensure => directory,
mode => 0644,
owner => root,
group => root,
require => Package["httpd"],
before => File["/etc/apache2/apache2.conf"],
}
file { "/etc/apache2/envvars":
ensure => present,
content => template("apache/apache2.envvars.erb"),
mode => 0644,
owner => root,
group => root,
require => Package["httpd"],
notify => Service["apache2"],
}
file { "/etc/apache2/ports.conf":
ensure => present,
content => "# HTTP server disabled\n"
mode => 0644,
owner => root,
group => root,
notify => Service["apache2"],
}
file { "/etc/apache2/apache2.conf":
ensure => present,
content => template("apache/apache2.conf.erb"),
mode => 0644,
owner => root,
group => root,
require => File["/etc/apache2/envvars", "/etc/apache2/ports.conf" ],
notify => Service["apache2"],
}
service { "apache2":
ensure => running,
enable => true,
require => File["/etc/apache2/apache2.conf"],
}
}
class apache::debian::server inherits apache::debian::common {
File["/etc/apache2/ports.conf"] {
content => "NameVirtualHost *:80\nListen80\n"
}
}
define apache::debian::site($aliases, $root, $config, $redirect) {
$site_conf = "/etc/apache2/sites-available/${name}.conf"
if $name == "default" {
$site_fqdn = $fqdn
} else {
$site_fqdn = $name
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}"],
}
}
file { "/srv/www/log/http/${site_fqdn}":
ensure => directory,
mode => 0755,
owner => root,
group => root,
before => File["${site_conf}"],
}
}
}
file { "${site_conf}":
ensure => present,
mode => 0644,
owner => root,
group => root,
notify => Service["httpd"],
}
if $config {
File["${site_conf}"] {
source => $config,
}
}
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"),
}
}
}
class apache::debian::sslserver inherits apache::debian::common {
file { [ "/srv/www/https",
"/srv/www/https/${fqdn}",
"/srv/www/log/https",
"/srv/www/log/https/${fqdn}", ]:
ensure => directory,
mode => 0644,
owner => root,
group => root,
require => Package["httpd"],
before => File["/etc/apache2/apache2.conf"],
}
apache::debian::a2enmod { "ssl": }
}
define apache::debian::configfile($source, $content, $http, $https) {
file { "/etc/apache2/conf.d/${name}":
ensure => present,
mode => 0644,
owner => root,
group => root,
notify => Service["apache2"],
require => Package["httpd"],
}
if $source {
File["/etc/apache2/conf.d/${name}"] {
source => $source,
}
}
if $content {
File["/etc/apache2/conf.d/${name}"] {
content => $content,
}
}
}
# Enable module on Debian/Ubuntu Apache.
#
# === Parameters
#
# $name:
# Module name.
# $source:
# Source for optional module configuration.
# $content:
# Content for optional module configuration.
# See also $source.
# $require:
# Dependencies for the module file.
#
define apache::debian::a2enmod($source="", $content="") {
exec { "a2enmod-${name}":
path => "/bin:/usr/bin:/sbin:/usr/sbin",
command => "a2enmod ${name}",
unless => "test -h /etc/apache2/mods-enabled/${name}.load",
notify => Service["apache2"],
require => Package["httpd"],
}
if $source or $content {
file { "/etc/apache2/mods-available/${name}.conf":
mode => 0644,
owner => root,
group => root,
notify => Service["apache2"],
before => Exec["a2enmod-${name}"],
}
if $source {
File["/etc/apache2/mods-available/${name}.conf"] {
source => $source,
}
}
if $content {
File["/etc/apache2/mods-available/${name}.conf"] {
content => $content,
}
}
}
}
# Enable virtual host on Debian/Ubuntu Apache.
#
# === Parameters
#
# $name:
# FQDN of virtual host.
#
define apache::debian::a2ensite() {
exec { "a2ensite-${name}":
path => "/bin:/usr/bin:/sbin:/usr/sbin",
command => "a2ensite ${name}",
unless => $name ? {
"default" => "test -h /etc/apache2/sites-enabled/000-default",
default => "test -h /etc/apache2/sites-enabled/${name}",
},
notify => Service["apache2"],
require => Package["httpd"],
}
}