From 759e0dc42fd62746fea0e740d88c9b210723af67 Mon Sep 17 00:00:00 2001 From: Thomas Bellman <bellman@nsc.liu.se> Date: Fri, 3 May 2024 11:43:18 +0200 Subject: [PATCH] Manage Include directives without managing the file. This adds support for the new value 'onlyinclude' for the $ensure parameter of apache::include_file. Setting 'onlyinclude' will add an Include directive to the main httpd.conf file without installing (or otherwise managing) the file that is included. This is useful if the included file is installed in some other way, e.g. via package (RPM/Deb/ebuild/...) installation, or by using the concat::file definition. The latter is the direct motivation for this feature; we will use that to manage Listen directives in the upcoming commit. --- manifests/include_file.pp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/manifests/include_file.pp b/manifests/include_file.pp index ce29992..37c805b 100644 --- a/manifests/include_file.pp +++ b/manifests/include_file.pp @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2022 Thomas Bellman. +# Copyright (C) 2014-2024 Thomas Bellman. # Licensed under the GNU LGPL v3+; see the README file for more information. @@ -15,7 +15,8 @@ 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'. + # must be specified when the ensure parameter is set to 'present' + # or 'noinclude'. # $content = undef, $source = undef, @@ -35,6 +36,12 @@ define apache::include_file( # useful if the file should be included from another include # file. # + # - 'onlyinclude' + # Create the Include directive in the main httpd.conf file, + # but do not manage the actual file. This is useful if the + # file is managed in some other way (e.g. being installed + # from an RPM package). + # $ensure = 'present' ) { @@ -59,6 +66,9 @@ define apache::include_file( ensure => absent, notify => Class[apache::service]; } } + 'onlyinclude': { + # Nothing to do here + } default: { fail("Apache::Include_file[${title}]: ", "Bad parameter ensure: ${ensure}") @@ -67,10 +77,14 @@ define apache::include_file( case $ensure { - 'present': { + 'present', 'onlyinclude': { # 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. + $filerequire = $ensure ? { + 'present' => File[$includefile], + 'onlyinclude' => [], + } ensure_line { "apache::include_file::include::${name}": file => $apache::configfile, @@ -78,7 +92,7 @@ define apache::include_file( addhow => append, require => [ Regexp_replace_lines['apache::base::no_include_all'], - File[$includefile] + $filerequire, ], notify => Class[apache::service]; } -- GitLab