transport.pp 2.2 KB
Newer Older
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
1
2
3
4
5
6
7
8
9
# == 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.
Erinn Looney-Triggs's avatar
Erinn Looney-Triggs committed
10
# [*nexthop*]     - A string to define where and how to deliver the mail. See transport(5).
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
11
12
13
14
15
16
17
18
19
20
#
# === Requires
#
# - Class["postfix"]
# - Postfix::Hash["/etc/postfix/transport"]
# - Postfix::Config["transport_maps"]
# - augeas
#
# === Examples
#
21
#   node 'toto.example.com' {
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
22
23
24
#
#     include postfix
#
25
#     postfix::hash { '/etc/postfix/transport':
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
26
27
#       ensure => present,
#     }
28
29
#     postfix::config { 'transport_maps':
#       value => 'hash:/etc/postfix/transport',
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
30
#     }
31
#     postfix::transport { 'mailman.example.com':
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
32
#       ensure      => present,
33
#       destination => 'mailman',
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
34
35
#     }
#   }
36
#
37
define postfix::transport (
38
39
  $destination=undef,
  $nexthop=undef,
40
41
42
  $file='/etc/postfix/transport',
  $ensure='present'
) {
43
  include ::postfix::augeas
44

45
46
47
48
49
50
  validate_string($destination)
  validate_string($nexthop)
  validate_string($file)
  validate_absolute_path($file)
  validate_string($ensure)

51
52
  case $ensure {
    'present': {
53
54
55
56
57
58
      if ($destination) {
        $change_destination = "set pattern[. = '${name}']/transport '${destination}'"
      } else {
        $change_destination = "clear pattern[. = '${name}']/transport"
      }

59
      if ($nexthop) {
60
        $change_nexthop = "set pattern[. = '${name}']/nexthop '${nexthop}'"
61
      } else {
62
        $change_nexthop = "clear pattern[. = '${name}']/nexthop"
63
      }
64
65
66
67
68
69

      $changes = [
        "set pattern[. = '${name}'] '${name}'",
        $change_destination,
        $change_nexthop,
      ]
70
71
72
73
74
75
76
    }

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

    default: {
77
      fail "\$ensure must be either 'present' or 'absent', got '${ensure}'"
78
79
80
81
    }
  }

  augeas {"Postfix transport - ${name}":
82
83
84
    lens    => 'Postfix_Transport.lns',
    incl    => $file,
    changes => $changes,
85
86
87
88
    require => [
      Package['postfix'],
      Augeas::Lens['postfix_transport'],
      ],
89
    notify  => Postfix::Hash['/etc/postfix/transport'],
90
91
  }
}