transport.pp 1.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#== Definition: postfix::transport
#
#Manages content of the /etc/postfix/transport map.
#
#Parameters:
#- *name*: name of address postfix will lookup. See transport(5).
#- *destination*: where the emails will be delivered to. See transport(5).
#- *ensure*: present/absent, defaults to present.
#
#Requires:
#- Class["postfix"]
#- Postfix::Hash["/etc/postfix/transport"]
#- Postfix::Config["transport_maps"]
14
#- augeas
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
#Example usage:
#
#  node "toto.example.com" {
#
#    include postfix
#
#    postfix::hash { "/etc/postfix/transport":
#      ensure => present,
#    }
#    postfix::config { "transport_maps":
#      value => "hash:/etc/postfix/transport"
#    }
#    postfix::transport { "mailman.example.com":
#      ensure      => present,
#      destination => "mailman",
#    }
#  }
#
34
35
define postfix::transport (
  $destination,
36
  $nexthop='',
37
38
39
40
41
42
43
  $file='/etc/postfix/transport',
  $ensure='present'
) {
  include postfix::augeas

  case $ensure {
    'present': {
44
45
46
47
48
49
50
51
      if ($nexthop) {
        $changes = [
          "set pattern[. = '${name}'] '${name}'",
          "set pattern[. = '${name}']/transport '${destination}'",
          # TODO: support nexthop
          "set pattern[. = '${name}']/nexthop '${nexthop}'",
        ]
      } else {
52
53
54
55
56
57
        $changes = [
          "set pattern[. = '${name}'] '${name}'",
          "set pattern[. = '${name}']/transport '${destination}'",
          # TODO: support nexthop
          "clear pattern[. = '${name}']/nexthop",
        ]
58
      }
59
60
61
62
63
64
65
66
67
68
69
70
71
    }

    'absent': {
      $changes = "rm pattern[. = '${name}']"
    }

    default: {
      fail("Wrong ensure value: ${ensure}")
    }
  }

  augeas {"Postfix transport - ${name}":
    load_path => '/usr/share/augeas/lenses/contrib/',
72
73
    lens      => 'Postfix_Transport.aug',
    incl      => $file,
74
75
76
    changes   => $changes,
    require   => [Package['postfix'], Augeas::Lens['postfix_transport']],
    notify    => Exec['generate /etc/postfix/transport.db'],
77
78
  }
}