Defined Type: postfix::canonical

Defined in:
manifests/canonical.pp

Summary

Manage content of the Postfix canonical map

Overview

This type manages content of the /etc/postfix/canonical map.

Examples:

Basic usage and required setup

# This defined type requires the following resources:
# - Class["postfix"]
# - Postfix::Hash["/etc/postfix/canonical"]
# - Postfix::Config["canonical_maps"] or Postfix::Config["sender_canonical_maps"] or Postfix::Config["recipient_canonical_maps"]
include postfix
postfix::hash { '/etc/postfix/recipient_canonical':
  ensure => present,
}
postfix::config { 'canonical_alias_maps':
  value => 'hash:/etc/postfix/recipient_canonical',
}
postfix::canonical { 'user@example.com':
  file        => '/etc/postfix/recipient_canonical',
  ensure      => present,
  destination => 'root',
}

Parameters:

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

    Intended state of the resource

  • destination (String)

    Where the emails will be delivered to.

  • file (Stdlib::Absolutepath) (defaults to: undef)

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

  • lookup_table_suffix (String[1]) (defaults to: 'db')

    Depends on the lookup table type, which is used on the postfix::hash and postfix::config resources. Defaults to ‘db’, the suffix of the “hash” type.

See Also:



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
# File 'manifests/canonical.pp', line 39

define postfix::canonical (
  String                   $destination,
  Enum['present','absent'] $ensure              = 'present',
  Stdlib::Absolutepath     $file                = undef,
  String[1]                $lookup_table_suffix = 'db',
) {
  include postfix

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

  case $ensure {
    'present': {
      $changes = [
        "set pattern[. = '${name}'] '${name}'",
        "set pattern[. = '${name}']/destination '${destination}'",
      ]
    }

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

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

  augeas { "Postfix canonical - ${name}":
    incl    => $_file,
    lens    => 'postfix_canonical.lns',
    changes => $changes,
    require => Package['postfix'],
    notify  => Exec["generate ${_file}.${lookup_table_suffix}"],
  }
}