From c92afd3d20f935ffb3105df8bf912a7851a602e3 Mon Sep 17 00:00:00 2001 From: Thomas Bellman <bellman@nsc.liu.se> Date: Wed, 10 Aug 2022 17:38:20 +0200 Subject: [PATCH] New ensure value 'noinclude' for apache::include_file. This adds support to the apache::include_file definition for putting a config file in place in the conf.d directory, but without adding an Include directive in httpd.conf (it will in fact remove any Include directive referencing the file from httpd.conf). This is done by specifying "ensure => 'noinclude'" to apache::include_file. This is useful if you want to create a configuration fragment that is supposed to be Include:d from within e.g. a <VirtualHost> section. An example is the NSC munin module which wants to do exactly that. --- manifests/include_file.pp | 61 +++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/manifests/include_file.pp b/manifests/include_file.pp index 0a13fc0..482dea2 100644 --- a/manifests/include_file.pp +++ b/manifests/include_file.pp @@ -10,13 +10,33 @@ * 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') +define apache::include_file( + # The content/source of the include file. These two parameters + # have the same meaning as in the file type. Exactly one of them + # must be specified when the ensure parameter is set to 'present'. + # + $content = undef, + $source = undef, + + # One of: + # - 'present' + # The include file should be installed and be included from + # the main httpd.conf file. + # + # - 'absent' + # The include file should be removed. Any Include directive + # mentioning it in the main httpd.conf file will be removed. + # + # - 'noinclude' + # Install the include file, but do not create any Include + # directive for it in the main httpd.conf file. This is + # useful if the file should be included from another include + # file. + # + $ensure = 'present' +) { include apache @@ -24,10 +44,7 @@ define apache::include_file($content=undef, $source=undef, $ensure='present') 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. + 'present', 'noinclude': { file { $includefile: ensure => file, @@ -35,6 +52,25 @@ define apache::include_file($content=undef, $source=undef, $ensure='present') content => $content, source => $source, notify => Class[apache::service]; } + } + 'absent': { + file { + $includefile: + ensure => absent, notify => Class[apache::service]; + } + } + default: { + fail("Apache::Include_file[${title}]: ", + "Bad parameter ensure: ${ensure}") + } + } + + case $ensure + { + 'present': { + # Put the Include directive in place after the included file; if + # the machine reboots in the middle, we do not want to needlessly + # hose up the Apache service. ensure_line { "apache::include_file::include::${name}": file => $apache::configfile, @@ -47,8 +83,7 @@ define apache::include_file($content=undef, $source=undef, $ensure='present') notify => Class[apache::service]; } } - - 'absent': { + 'absent', 'noinclude': { # 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. @@ -59,10 +94,6 @@ define apache::include_file($content=undef, $source=undef, $ensure='present') before => File[$includefile], notify => Class[apache::service]; } - file { - $includefile: - ensure => absent, notify => Class[apache::service]; - } } default: { -- GitLab