Notify prosody when its certificates change
[mirror/dsa-puppet.git] / modules / apache2 / manifests / site.pp
index dc9b1ce..b847c22 100644 (file)
@@ -1,68 +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 (
-       $source=undef,
-       $content=undef,
-       $ensure=present,
-       $site=undef
+  Optional[String] $source = undef,
+  Optional[String] $content = undef,
+  Enum['present','absent'] $ensure = 'present',
+  String $site = $name
 ) {
-
-       include apache2
-
-       case $ensure {
-               present: {
-                       if ! ($source or $content) {
-                               fail ( "No configuration found for ${name}" )
-                       }
-               }
-               absent:  {}
-               default: { fail ( "Unknown ensure value: '$ensure'" ) }
-       }
-
-       if $site {
-               $base = $site
-       } else {
-               $base = $name
-       }
-
-       $target = "/etc/apache2/sites-available/${base}"
-
-       $link_target = $ensure ? {
-               present => $target,
-               absent  => absent
-       }
-
-       if $content {
-               file { $target:
-                       ensure  => $ensure,
-                       content => $content,
-                       require => Package['apache2'],
-                       notify  => Exec['service apache2 reload'],
-               }
-       } else {
-               file { $target:
-                       ensure  => $ensure,
-                       source  => $source,
-                       require => Package['apache2'],
-                       notify  => Exec['service apache2 reload'],
-               }
-       }
-
-       $symlink = "/etc/apache2/sites-enabled/${name}.conf"
-
-       file { "/etc/apache2/sites-enabled/${name}":
-               ensure => absent,
-               notify  => Exec['service apache2 reload'],
-       }
-
-       if $ensure == present {
-               file { $symlink:
-                       ensure => link,
-                       target => $link_target,
-                       notify  => Exec['service apache2 reload'],
-               }
-       } else {
-               file { $symlink:
-                       ensure => absent,
-                       notify  => Exec['service apache2 reload'],
-               }
-       }
+  include apache2
+
+  if $ensure == 'present' {
+    if ! ($source or $content) {
+      fail ( "No configuration (source or content) found for ${name}" )
+    }
+  }
+
+  $target = "/etc/apache2/sites-available/${site}"
+  $symlink = "/etc/apache2/sites-enabled/${name}.conf"
+  $link_ensure = $ensure ? {
+    present => link,
+    absent  => absent,
+  }
+
+  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'],
+  }
 }