Defined Type: dovecot::config
- Defined in:
- manifests/config.pp
Summary
This type manages a single config entry.Overview
Dovecot uses its own config format. This format basically allows to define a hierarchy of configuration sections (and syntactically identical filters, so they will just be treated as sections by this module).
Since in puppet, we want to map each single config entry as its own resource, the hierarchy has been “flattened” to hierarchical keys.
A key/value pair ‘foo = bar` nested in a `section` object, would look like this in a dovecot config file:
“‘json section
foo =
“‘
To reference this key in a dovecot::config variable, you would use the notation ‘section.foo`.
Title/Name format
This module can manage both a global dovecot.conf and single conf.d files. The module author recommends single file setups for puppet-managed hosts, but users can choose to split their managed config into single files.
To specify which file a config entry should got to, you can use the ‘file` parameter.
For convenience reasons, however, this resource also allows to encode the values for $sections, $key, and $file into the resource’s name (which is usally the same as its title).
If the $name of the resource matches the format “[<file>:]<name>”, and all of $file, $sections, and $key have not been specified, the values from the name are used. This simplifies creating unique resources for identical settings in different files.
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 |
# File 'manifests/config.pp', line 69
define dovecot::config (
Variant[Boolean, Integer, String] $value,
Optional[String] $comment = undef,
Enum['present', 'absent'] $ensure = 'present',
Optional[String] $file = undef,
Optional[String] $key = undef,
Optional[Array[String]] $sections = undef,
) {
if (!$key and !$sections and !$file and $name =~ /\A(?:([^:]+):)?(.+\.)?([^.]+)\z/) {
$configfile = $1
$configsections = $2 ? {
Undef => [],
default => split($2, '\.'),
}
$configkey = $3
} else {
$configfile = $file
$configsections = pick($sections, [])
$configkey = pick($key, $name)
}
$full_file = $configfile ? {
Undef => "${dovecot::config_path}/dovecot.conf",
default => "${dovecot::config_path}/conf.d/${configfile}.conf"
}
$_full_key = join($configsections + $configkey, '/')
$full_key = $key ? {
/\A!/ => "${_full_key} ${value}",
default => $_full_key,
}
dovecot::configentry { "dovecot config ${full_file} ${full_key}":
ensure => $ensure,
file => $full_file,
sections => $configsections,
key => $configkey,
value => $value,
comment => $comment,
notify => Class['dovecot::service'],
}
}
|