Merge branch 'fordsa' of https://git.adam-barratt.org.uk/git/mirror/dsa-puppet
[mirror/dsa-puppet.git] / modules / apache2 / manifests / site.pp
index 8fa5fdf..b847c22 100644 (file)
@@ -1,61 +1,40 @@
+# Install and enable an apache site
+#
+# @param source  source of the apache vhost file
+# @param content content of the apache vhost file
+# @param ensure  present or absent
+# @param site    site name
 define apache2::site (
-       $config = undef,
-       $template = false,
-       $ensure = present,
-       $site = undef
+  Optional[String] $source = undef,
+  Optional[String] $content = undef,
+  Enum['present','absent'] $ensure = 'present',
+  String $site = $name
 ) {
+  include apache2
 
-       include apache2
+  if $ensure == 'present' {
+    if ! ($source or $content) {
+      fail ( "No configuration (source or content) found for ${name}" )
+    }
+  }
 
-       if $ensure == present {
-               if ! ($config or $template) {
-                       fail ( "No configuration found for ${name}" )
-               }
-       }
+  $target = "/etc/apache2/sites-available/${site}"
+  $symlink = "/etc/apache2/sites-enabled/${name}.conf"
+  $link_ensure = $ensure ? {
+    present => link,
+    absent  => absent,
+  }
 
-       if $site {
-               $base = $site
-       } else {
-               $base = $name
-       }
-
-       $target = "/etc/apache2/sites-available/${base}"
-
-       $link_target = $ensure ? {
-               present => $target,
-               absent  => absent,
-               default => fail ( "Unknown ensure value: '$ensure'" ),
-       }
-
-       case $template {
-               false: {
-                       file { $target:
-                               ensure  => $ensure,
-                               source  => $config,
-                               require => Package['apache2'],
-                               notify  => Service['apache2'],
-                       }
-               }
-               default: {
-                       file { $target:
-                               ensure  => $ensure,
-                               content => template($template),
-                               require => Package['apache2'],
-                               notify  => Service['apache2'],
-                       }
-               }
-       }
-
-       if $ensure == present {
-               file { "/etc/apache2/sites-enabled/${name}":
-                       ensure => link,
-                       target => $link_target,
-                       notify => Service['apache2'],
-               }
-       } else {
-               file { "/etc/apache2/sites-enabled/${name}":
-                       ensure => absent,
-                       notify => Service['apache2'],
-               }
-       }
+  file { $target:
+    ensure  => $ensure,
+    content => $content,
+    source  => $source,
+    require => Package['apache2'],
+    notify  => Exec['service apache2 reload'],
+  }
+  file { $symlink:
+    ensure => $link_ensure,
+    target => $target,
+    notify => Exec['service apache2 reload'],
+  }
 }