From 1e3d18cb8ab1c76b5b015029fe38b30702ca1961 Mon Sep 17 00:00:00 2001
From: Thomas Bellman <bellman@nsc.liu.se>
Date: Thu, 6 Feb 2014 11:40:49 +0100
Subject: [PATCH] Add definition for managing global module configuration.

This adds the definition apache::module::globalconfig for managing
global module configuration.  It is basically a thin wrapper around
apache::include_file, giving a nicer API for specifying global
configuration of Apache modules.
---
 manifests/init.pp         | 56 +++++++++++++++++++++++++++++++++++++++
 templates/module.conf.erb | 11 ++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 templates/module.conf.erb

diff --git a/manifests/init.pp b/manifests/init.pp
index f73421f..2bdb70e 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -165,3 +165,59 @@ define apache::include_file($content=undef, $source=undef, $ensure='present')
 	}
     }
 }
+
+
+
+/*
+ * Define global configuration for an Apache module.
+ *
+ * To be used by classes installing and configuring Apache modules.
+ * Such classes should use this definition to set some reasonable
+ * default configuration.  Users wanting a different configuration
+ * should inherit that class and override this resource.
+ *
+ * Configuration will be written to an "include file" in $apache::configdir,
+ * and an Include directive will be added to the main Apache
+ * httpd.conf file loading that specific file.  (Therefore, there
+ * must not be any wildcard Include directive in httpd.conf; the
+ * apache::base class ensures this.)
+ *
+ * Parameters:
+ *
+ *  - name:
+ *    The name of the config file in /etc/httpd/conf.d that will be
+ *    written.  The suffix ".conf" will be automatically added.
+ *
+ *  - loadmodule:
+ *    Parameters to the LoadModule directive.
+ *
+ *  - directives:
+ *    List of directive lines.  Users should usually use the 'defaultoptions'
+ *    and 'options' parameters, but since some directives can occur multiple
+ *    times, a way of specifying those is needed, thus this parameter.
+ *
+ *  - defaultoptions, options:
+ *    Hashes of directive names and parameters to them.  These two hashes
+ *    will be joined, and settings in the latter will override settings in
+ *    the former.  The intent is that a class for an Apache module will set
+ *    'defaultoptions' to some reasonable defaults, and users wanting to
+ *    add to or override those will set 'options'.
+ *       Setting the value of a specific option to false will exclude it
+ *    from the config file.
+ *
+ *  - ensure:
+ *    One of 'present' or 'absent'.  Setting to 'absent' will remove the
+ *    module configuration file, and remove the Include directive for it
+ *    from the main Apache httpd.conf file.
+ */
+
+define apache::module::globalconfig(
+    $loadmodule, $directives=[], $defaultoptions, $options={},
+    $ensure='present')
+{
+    apache::include_file {
+	$name:
+	    ensure => $ensure,
+	    content => template('apache/module.conf.erb');
+    }
+}
diff --git a/templates/module.conf.erb b/templates/module.conf.erb
new file mode 100644
index 0000000..a98cf02
--- /dev/null
+++ b/templates/module.conf.erb
@@ -0,0 +1,11 @@
+LoadModule <%= @loadmodule %>
+
+<% @directives.each do |line| -%>
+<%=   line %>
+<% end -%>
+
+<% @defaultoptions.merge(@options).sort.each do |optname,params| -%>
+<%    if params != false -%>
+<%=      (optname + '  ' + params).rstrip() %>
+<%    end -%>
+<% end -%>
-- 
GitLab