1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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
|
# @summary Manages the contents of the virtual map.
#
# Manages content of the /etc/postfix/virtual map.
#
# @example Minimum Requirements
# include postfix
# postfix::hash { "/etc/postfix/virtual":
# ensure => present,
# }
# postfix::config { "virtual_alias_maps":
# value => "hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual_regexp"
# }
#
# @example Route mail to local users
# postfix::virtual { "user@example.com":
# ensure => present,
# destination => ['root', 'postmaster'],
# }
#
# @example Regex example
# postfix::virtual { "/.+@.+/"
# ensure => present,
# file => '/etc/postfix/virtual_regexp',
# destination => 'root',
# }
#
# @example Route mail bound for 'user@example.com' to root.
# postfix::virtual {'user@example.com':
# ensure => present,
# destination => 'root',
# }
#
# @param ensure
# A string whose valid values are present or absent.
#
# @param destination
# A string defining where the e-mails will be delivered to, (virtual(8)).
# Example: `root`
#
# @param file
# A string defining the location of the virtual map, pre hash.
# If not defined "${postfix::confdir}/virtual" will be used as path.
# Example: `/etc/postfix/my_virtual_map`.
#
# @see https://www.postfix.org/virtual.8.html
#
define postfix::virtual (
Variant[String, Array[String]] $destination,
Enum['present', 'absent'] $ensure = 'present',
Optional[Stdlib::Absolutepath] $file = undef
) {
include postfix
$_file = pick($file, "${postfix::confdir}/virtual")
$dest_sets = [$destination].flatten.map |$i, $d| {
$idx = $i+1
"set \$entry/destination[${idx}] '${d}'"
}
case $ensure {
'present': {
$changes = [
"defnode entry pattern[. = '${name}'] '${name}'",
'rm $entry/destination',
$dest_sets,
].flatten
}
'absent': {
$changes = "rm pattern[. = '${name}']"
}
default: {
fail "\$ensure must be either 'present' or 'absent', got '${ensure}'"
}
}
augeas { "Postfix virtual - ${name}":
incl => $_file,
lens => 'Postfix_Virtual.lns',
changes => $changes,
}
if defined(Package['postfix']) {
Package['postfix'] -> Postfix::Virtual[$title]
}
if defined(Postfix::Hash[$_file]) {
Postfix::Virtual[$title] ~> Postfix::Hash[$_file]
}
}
|