Defined Type: postfix::transport

Defined in:
manifests/transport.pp

Summary

Manage the transport map of postfix

Overview

Manages content of the /etc/postfix/transport map.

Examples:

Simple transport map config

include postfix
postfix::hash { '/etc/postfix/transport':
  ensure => present,
}
postfix::config { 'transport_maps':
  value => 'hash:/etc/postfix/transport, regexp:/etc/postfix/transport_regexp',
}
postfix::transport {
  'mailman.example.com':
     ensure      => present,
     destination => 'mailman';
  'slow_transport':
     ensure      => present,
     nexthop     => '/^user-.*@mydomain\.com/'
     file        => '/etc/postfix/transport_regexp',
     destination => 'slow'
}

Parameters:

  • ensure (Enum['present', 'absent']) (defaults to: 'present')

    Defines whether the transport entry is present or not. Value can either be present or absent.

  • destination (Optional[String]) (defaults to: undef)

    The destination to be delivered to (transport(5)). Example: ‘mailman`.

  • nexthop (Optional[String]) (defaults to: undef)

    A string to define where and how to deliver the mail (transport(5)). Example: ‘[smtp.google.com]:25`.

  • file (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Where to create the file. If not defined “$postfixpostfix::confdir/transport” will be used as path.

See Also:



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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'manifests/transport.pp', line 41

define postfix::transport (
  Enum['present', 'absent']      $ensure      = 'present',
  Optional[String]               $destination = undef,
  Optional[String]               $nexthop     = undef,
  Optional[Stdlib::Absolutepath] $file        = undef,
) {
  include postfix

  $_file = pick($file, "${postfix::confdir}/transport")

  $smtp_nexthop = (String($nexthop) =~ /\[.*\]/)

  case $ensure {
    'present': {
      if ($smtp_nexthop) {
        $change_destination = "rm pattern[. = '${name}']/transport"
      } else {
        if ($destination) {
          $change_destination = "set pattern[. = '${name}']/transport '${destination}'"
        } else {
          $change_destination = "clear pattern[. = '${name}']/transport"
        }
      }

      if ($nexthop) {
        # This is some paranoia over splitting.  We can't do a simple split here, as there
        # could be ipv6 addrs in a nexthop's host.  So we're definitely into neeeding a regexp.
        # The regexp needs to be 'the same base' as used in smtp_nexthop above, while also
        # capturing the port.
        # From https://github.com/voxpupuli/puppet-postfix/issues/241, this exists
        # to handle [host]:port nexthop.  Other cases are handled by simply passing nexthop
        # straight through.
        $nexthop_match = $nexthop.match(/(:?\[.*\]):(\d+)/)
        # If this matched, we'll have a length of 3: [whole string, host, port].
        if ($nexthop_match =~ Array and $nexthop_match.length == 3) {
          $change_nexthop = [
            "rm pattern[. = '${name}']/nexthop",
            "set pattern[. = '${name}']/host '${nexthop_match[1]}'",
            "set pattern[. = '${name}']/port '${nexthop_match[2]}'",
          ]
        } else {
          # If it didn't match, we just report the nexthop unmodified; remove any breakout of
          # host/port that may have existed.
          $change_nexthop = [
            "rm pattern[. = '${name}']/host",
            "rm pattern[. = '${name}']/port",
            "set pattern[. = '${name}']/nexthop '${nexthop}'",
          ]
        }
      } else {
        $change_nexthop = [
          "clear pattern[. = '${name}']/nexthop",
          "rm pattern[. = '${name}']/host",
          "rm pattern[. = '${name}']/port",
        ]
      }

      $changes = flatten([
          "set pattern[. = '${name}'] '${name}'",
          $change_destination,
          $change_nexthop,
      ])
    }

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

    default: {
      fail "\$ensure must be either 'present' or 'absent', got '${ensure}'"
    }
  }

  augeas { "Postfix transport - ${name}":
    lens    => 'Postfix_Transport.lns',
    incl    => $_file,
    changes => $changes,
  }

  if defined(Package['postfix']) {
    Package['postfix'] -> Postfix::Transport[$title]
  }

  if defined(Postfix::Hash[$_file]) {
    Postfix::Transport[$title] ~> Postfix::Hash[$_file]
  }
}