puppet 4 foo
[mirror/dsa-puppet.git] / modules / apache2 / manifests / site.pp
index 263c6d8..ff1ee20 100644 (file)
@@ -1,14 +1,20 @@
 define apache2::site (
-       $config = undef,
-       $template = false,
-       $ensure = present,
-       $site = undef
+       $source=undef,
+       $content=undef,
+       $ensure=present,
+       $site=undef
 ) {
 
        include apache2
 
-       if ! ($config or $template) {
-               err ( "No configuration found for ${name}" )
+       case $ensure {
+               present: {
+                       if ! ($source or $content) {
+                               fail ( "No configuration found for ${name}" )
+                       }
+               }
+               absent:  {}
+               default: { fail ( "Unknown ensure value: '$ensure'" ) }
        }
 
        if $site {
@@ -21,39 +27,46 @@ define apache2::site (
 
        $link_target = $ensure ? {
                present => $target,
-               absent  => absent,
-               default => err ( "Unknown ensure value: '$ensure'" ),
+               absent  => absent
        }
 
-       case $template {
-               false: {
-                       file { $target:
-                               ensure  => $ensure,
-                               source  => $config,
-                               require => Package['apache2'],
-                               notify  => Service['apache2'],
-                       }
+       if $content {
+               file { $target:
+                       ensure  => $ensure,
+                       content => $content,
+                       require => Package['apache2'],
+                       notify  => Exec['service apache2 reload'],
                }
-               default: {
-                       file { $target:
-                               ensure  => $ensure,
-                               content => template($template),
-                               require => Package['apache2'],
-                               notify  => Service['apache2'],
-                       }
+       } else {
+               file { $target:
+                       ensure  => $ensure,
+                       source  => $source,
+                       require => Package['apache2'],
+                       notify  => Exec['service apache2 reload'],
                }
        }
 
-       if $ensure == present {
+       if $::lsbmajdistrelease <= '7' {
+               $symlink = "/etc/apache2/sites-enabled/${name}"
+       } else {
+               $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 => Service['apache2'],
+                       notify  => Exec['service apache2 reload'],
                }
        } else {
-               file { "/etc/apache2/sites-enabled/${name}":
+               file { $symlink:
                        ensure => absent,
-                       notify => Service['apache2'],
+                       notify  => Exec['service apache2 reload'],
                }
        }
 }