Defined Type: apache::custom_config
- Defined in:
- manifests/custom_config.pp
Summary
Adds a custom configuration file to the Apache server's `conf.d` directory.Overview
If the file is invalid and this defined type’s ‘verify_config` parameter’s value is ‘true`, Puppet throws an error during a Puppet run.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'manifests/custom_config.pp', line 54
define apache::custom_config (
Enum['absent', 'present'] $ensure = 'present',
Stdlib::Absolutepath $confdir = $apache::confd_dir,
Optional[String] $content = undef,
Apache::Vhost::Priority $priority = 25,
Optional[String] $source = undef,
Variant[String, Array[String], Array[Array[String]]] $verify_command = $apache::params::verify_command,
Boolean $verify_config = true,
Optional[String] $filename = undef,
Optional[String] $owner = undef,
Optional[String] $group = undef,
Optional[Stdlib::Filemode] $file_mode = undef,
Boolean $show_diff = true,
) {
if $content and $source {
fail('Only one of $content and $source can be specified.')
}
if $ensure == 'present' and ! $content and ! $source {
fail('One of $content and $source must be specified.')
}
if $filename {
$_filename = $filename
} else {
if $priority {
$priority_prefix = "${priority}-"
} else {
$priority_prefix = ''
}
## Apache include does not always work with spaces in the filename
$filename_middle = regsubst($name, ' ', '_', 'G')
$_filename = "${priority_prefix}${filename_middle}.conf"
}
if ! $verify_config or $ensure == 'absent' {
$notifies = Class['Apache::Service']
} else {
$notifies = undef
}
$_file_path = "${confdir}/${_filename}"
$_file_mode = pick($file_mode, $apache::file_mode)
file { "apache_${name}":
ensure => $ensure,
path => $_file_path,
owner => $owner,
group => $group,
mode => $_file_mode,
content => $content,
source => $source,
show_diff => $show_diff,
require => Package['httpd'],
notify => $notifies,
}
if $ensure == 'present' and $verify_config {
exec { "syntax verification for ${name}":
command => $verify_command,
subscribe => File["apache_${name}"],
refreshonly => true,
notify => Class['Apache::Service'],
before => Exec["remove ${name} if invalid"],
require => Anchor['::apache::modules_set_up'],
}
$remove_command = ['/bin/rm', $_file_path]
exec { "remove ${name} if invalid":
command => $remove_command,
unless => [$verify_command],
subscribe => File["apache_${name}"],
refreshonly => true,
}
}
}
|