]> gitweb.fluxo.info Git - puppet-apache.git/commitdiff
Adds apache::site::manage
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 18 Jun 2016 16:29:50 +0000 (13:29 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 18 Jun 2016 16:29:50 +0000 (13:29 -0300)
manifests/site.pp
manifests/site/manage.pp [new file with mode: 0644]

index ff053b938eebf8268609a6c3874f1c918a9e6891..2c76a0183f9f088cf674cee45cbab1aec825e568 100644 (file)
@@ -122,6 +122,7 @@ define apache::site(
     ensure => absent,
   }
 
+  # Setup configuration
   apache::site::config { $name:
     ensure               => $ensure,
     source               => $source,
@@ -147,56 +148,13 @@ define apache::site(
     hosting_domain       => $hosting_domain,
   }
 
-  case $ensure {
-    'present': {
-      if ($docroot != false) and ($manage_docroot == true) {
-        if !defined(File["${docroot}"]) {
-          file { "${docroot}":
-            ensure  => present,
-            owner   => $owner,
-            group   => $group,
-            mode    => 0755,
-            recurse => false,
-          }
-        }
-        if !defined(Exec["check_docroot_${docroot}"]) {
-          # Ensure parent folder exist
-          exec { "check_docroot_${docroot}":
-            command => "/bin/mkdir -p ${docroot}",
-            unless  => "/bin/sh -c '[ -e ${docroot} ]'",
-            user    => root,
-            before  => File["${docroot}"],
-          }
-        }
-      }
-      exec { "/usr/sbin/a2ensite $vhost":
-        command => $::lsbdistcodename ? {
-          'wheezy' => "/usr/sbin/a2ensite $vhost.conf",
-          default  => "/usr/sbin/a2ensite $vhost",
-        },
-        unless  => "/bin/sh -c '[ -L ${apache::conf_sites}-enabled/$vhost.conf ] \
-                && [ ${apache::conf_sites}-enabled/$vhost.conf -ef ${apache::conf_sites}-available/$vhost.conf ]'",
-        require => Apache::Site::Config[$name],
-        notify  => Exec["reload-apache2"],
-      }
-    }
-    'absent': {
-      exec { "/usr/sbin/a2dissite $vhost":
-        command => $::lsbdistcodename ? {
-          'wheezy' => "/usr/sbin/a2dissite $vhost.conf",
-          default  => "/usr/sbin/a2dissite $vhost",
-        },
-        onlyif  => "/bin/sh -c '[ -L ${apache::conf_sites}-enabled/$vhost.conf ] \
-                && [ ${apache::conf_sites}-enabled/$vhost.conf -ef ${apache::conf_sites}-available/$vhost.conf ]'",
-        require => Apache::Site::Config[$name],
-        notify  => Exec["reload-apache2"],
-      }
-
-      file { "${apache::conf_sites}-enabled/$vhost.conf":
-        ensure => absent,
-        notify => Exec["reload-apache2"],
-      }
-    }
-    default: { err ("Unknown ensure value: '$ensure'") }
+  # Enable or disable accordingly
+  apache::site::manage { $name:
+    ensure         => $ensure,
+    docroot        => $docroot,
+    manage_docroot => $manage_docroot,
+    owner          => $owner,
+    group          => $group,
+    vhost          => $vhost,
   }
 }
diff --git a/manifests/site/manage.pp b/manifests/site/manage.pp
new file mode 100644 (file)
index 0000000..c04bec3
--- /dev/null
@@ -0,0 +1,61 @@
+define apache::site::manage(
+  $ensure          = 'present',
+  $docroot         = false,
+  $manage_docroot  = true,
+  $owner           = 'root',
+  $group           = 'root',
+  $vhost           = $name,
+) {
+  case $ensure {
+    'present': {
+      if ($docroot != false) and ($manage_docroot == true) {
+        if !defined(File["${docroot}"]) {
+          file { "${docroot}":
+            ensure  => present,
+            owner   => $owner,
+            group   => $group,
+            mode    => 0755,
+            recurse => false,
+          }
+        }
+        if !defined(Exec["check_docroot_${docroot}"]) {
+          # Ensure parent folder exist
+          exec { "check_docroot_${docroot}":
+            command => "/bin/mkdir -p ${docroot}",
+            unless  => "/bin/sh -c '[ -e ${docroot} ]'",
+            user    => root,
+            before  => File["${docroot}"],
+          }
+        }
+      }
+      exec { "/usr/sbin/a2ensite $vhost":
+        command => $::lsbdistcodename ? {
+          'wheezy' => "/usr/sbin/a2ensite $vhost.conf",
+          default  => "/usr/sbin/a2ensite $vhost",
+        },
+        unless  => "/bin/sh -c '[ -L ${apache::conf_sites}-enabled/$vhost.conf ] \
+                && [ ${apache::conf_sites}-enabled/$vhost.conf -ef ${apache::conf_sites}-available/$vhost.conf ]'",
+        require => Apache::Site::Config[$name],
+        notify  => Exec["reload-apache2"],
+      }
+    }
+    'absent': {
+      exec { "/usr/sbin/a2dissite $vhost":
+        command => $::lsbdistcodename ? {
+          'wheezy' => "/usr/sbin/a2dissite $vhost.conf",
+          default  => "/usr/sbin/a2dissite $vhost",
+        },
+        onlyif  => "/bin/sh -c '[ -L ${apache::conf_sites}-enabled/$vhost.conf ] \
+                && [ ${apache::conf_sites}-enabled/$vhost.conf -ef ${apache::conf_sites}-available/$vhost.conf ]'",
+        require => Apache::Site::Config[$name],
+        notify  => Exec["reload-apache2"],
+      }
+
+      file { "${apache::conf_sites}-enabled/$vhost.conf":
+        ensure => absent,
+        notify => Exec["reload-apache2"],
+      }
+    }
+    default: { err ("Unknown ensure value: '$ensure'") }
+  }
+}