From 3782c19712e8d9e540e336d2a939b2030401dbb4 Mon Sep 17 00:00:00 2001 From: Thomas Bellman <bellman@nsc.liu.se> Date: Mon, 29 Apr 2024 16:06:03 +0200 Subject: [PATCH] Add ensure parameter to apache::listen. This allows users to stop listening to specific URLs (address/ports). --- manifests/listen.pp | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/manifests/listen.pp b/manifests/listen.pp index a278be2..ef97c26 100644 --- a/manifests/listen.pp +++ b/manifests/listen.pp @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Thomas Bellman. +# Copyright (C) 2014-2024 Thomas Bellman. # Licensed under the GNU LGPL v3+; see the README file for more information. @@ -26,15 +26,42 @@ * combination more than once, so named virtual hosts need to coordinate * the set of listening addresses between themselves. This is not * enforced by this definition, but by Apache. + * + * To stop listening on a set of URLs, specify the 'ensure' parameter + * with the value 'absent'. If you just remove the apache::listen + * resource, the include file containing the Listen directives will be + * removed, but there will still be an Include directive referencing it, + * and Apache httpd will refuse to start! */ -define apache::listen($urls) +define apache::listen( + $urls = false, + $ensure = 'present', +) { include apache::listen::no_global_listen - apache::include_file { - "_Listen_${name}": - content => template('apache/listen.erb'); + case $ensure + { + 'present': { + if ($urls == false) { + fail("Apache::Listen[${title}]: Bad urls parameter, ${urls}") + } + apache::include_file { + "_Listen_${name}": + ensure => $ensure, + content => template('apache/listen.erb'); + } + } + 'absent': { + apache::include_file { + "_Listen_${name}": + ensure => $ensure; + } + } + default: { + fail("Apache::Listen[${title}]: Bad parameter ensure, ${ensure}") + } } } -- GitLab