Newer
Older
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
# Our default Postfix configuration disables all local delivery and therefore
# doesn't use the aliases file. Instead, any mail routing other than
# masquerading as stanford.edu needs to be handled by the recipients map.
# This creates a class that can be used to add and remove entries from the
# recipients map.
#
# Example of how to set a recipient:
#
# base::postfix::recipient { 'root@stanford.edu':
# ensure => 'alert-email@monitoring.stanford.edu'
# }
#
# Example of how to ensure there is no recipient map:
#
# base::postfix::recipient { 'luke': ensure => absent }
#
# Assumes that a command 'postmap hash:$file' has been defined that will
# rebuild the recipients map.
define base::postfix::recipient(
$ensure,
$file = '/etc/postfix/recipients'
) {
$pattern = "'^${name}'"
case $ensure {
'absent': {
exec { "rm-recipient-${name}":
command => "sed -i -e '/^${name}/d' ${file}",
onlyif => "grep ${pattern} ${file}",
notify => Exec["postmap hash:${file}"]
}
}
default: {
$line = "${name} ${ensure}"
exec { "add-recipient-${name}":
command => "echo '${line}' >> ${file}",
unless => "grep ${pattern} ${file}",
require => Package['postfix'],
notify => Exec["postmap hash:${file}"],
}
exec { "fix-recipient-${name}":
command => "sed -i -e 's/^${name}..*\$/${line}/' ${file}",
unless => "grep '^${line}\$' ${file}",
require => Exec["add-recipient-${name}"],
notify => Exec["postmap hash:${file}"],