Skip to content
Snippets Groups Projects
Commit 37d03646 authored by Thomas Bellman's avatar Thomas Bellman
Browse files

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.)
parent 9894cf6b
No related branches found
No related tags found
No related merge requests found
......@@ -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}")
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment