From 37d03646d2c3432a1cdecac4973232b3b3c6493c Mon Sep 17 00:00:00 2001 From: Thomas Bellman <bellman@nsc.liu.se> Date: Thu, 6 Feb 2014 10:39:05 +0100 Subject: [PATCH] New definition for managing included config files. This adds apache::include_file, a definition for managing "include files", put into /etc/httpd/conf.d and loaded using Include directives from the main httpd.conf configuration file. This can be used for e.g. managing virtual hosts and/or global configuration for Apache modules (like adding LoadModule directives). (It is expected that higher level defines will be added for those kind of things, so end-users don't need to use apache::include_file directly themselves.) --- manifests/init.pp | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index 566e2da..f73421f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -94,3 +94,74 @@ class apache::logdir($owner='root', $group='root', $mode=0700) require => Package['httpd'], before => Class[apache::service]; } } + + + +/* + * Manage an Apache config file in conf.d. + * + * This will manage a config file in the Apache configuration directory, + * and the needed Include directive in the main httpd.conf file. This + * can be used e.g. for managing global configuration for Apache modules + * (LoadModule directives being a good candidate), and/or virtual host + * declarations. + * + * The parameters 'content' and 'source' have the same meaning as in + * the file type. Exactly one of them must be specified when the + * 'ensure' parameter is set to 'present' (the default). + */ + +define apache::include_file($content=undef, $source=undef, $ensure='present') +{ + include apache + + $includefile = "${apache::configdir}/${name}.conf" + + case $ensure + { + 'present': { + # Put the included file into place before the Include directive; + # in case the machine reboots in the middle, we do not want to + # needlessly hose up the Apache service. + file { + $includefile: + ensure => file, + owner => 'root', group => 'root', mode => 0444, + content => $content, source => $source, + notify => Class[apache::service]; + } + ensure_line { + "apache::include_file::include::${name}": + file => $apache::configfile, + line => "Include conf.d/${name}.conf", + where => '^##--Include conf\.d/\*\.conf$', + addhow => append, + require => [ Ensure_line['apache::base::no_include_all'], + File[$includefile] ], + notify => Class[apache::service]; + } + } + + 'absent': { + # Remove the Include directive before the included file; in case + # the machine reboots in the middle, we do not want to needlessly + # hose up the Apache service. + delete_lines { + "apache::include_file::include::${name}": + file => $apache::configfile, + pattern => "\s*Include\s+conf\.d/${name}\.conf\s*$", + before => File[$includefile], + notify => Class[apache::service]; + } + file { + $includefile: + ensure => absent, notify => Class[apache::service]; + } + } + + default: { + fail("Apache::Include_file[${title}]: ", + "Bad parameter ensure: ${ensure}") + } + } +} -- GitLab