-
-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathvirtual.pp
88 lines (79 loc) · 2.2 KB
/
virtual.pp
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
# == Definition: postfix::virtual
#
# Manages content of the /etc/postfix/virtual map.
#
# === Parameters
#
# [*name*] - name of address postfix will lookup. See virtual(8).
# [*destination*] - a list of destinations where the emails will be delivered to. See virtual(8).
# [*ensure*] - present/absent, defaults to present.
# [*file*] - a string defining the location of the pre-hash map.
#
# === Requires
#
# - Class["postfix"]
# - Postfix::Hash["/etc/postfix/virtual"]
# - Postfix::Config["virtual_alias_maps"]
# - augeas
#
# === Examples
#
# node "toto.example.com" {
#
# include postfix
# # postfix::hash { "/etc/postfix/virtual":
# ensure => present,
# }
# postfix::config { "virtual_alias_maps":
# value => "hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual_regexp"
# }
# postfix::virtual { "[email protected]":
# ensure => present,
# destination => ['root', 'postmaster'],
# }
# postfix::virtual { "/.+@.+/"
# ensure => present,
# file => '/etc/postfix/virtual_regexp',
# destination => 'root',
# }
# }
define postfix::virtual (
Variant[String, Array[String]] $destination,
Optional[Stdlib::Absolutepath] $file=undef,
Enum['present', 'absent'] $ensure='present'
) {
include postfix
include postfix::augeas
$_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,
require => Augeas::Lens['postfix_virtual'],
}
if defined(Package['postfix']) {
Package['postfix'] -> Postfix::Virtual[$title]
}
if defined(Postfix::Hash[$_file]) {
Postfix::Virtual[$title] ~> Postfix::Hash[$_file]
}
}