Defined Type: postfix::virtual

Defined in:
manifests/virtual.pp

Summary

Manages the contents of the virtual map.

Overview

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

Examples:

Minimum Requirements

include postfix
postfix::hash { "/etc/postfix/virtual":
  ensure => present,
}
postfix::config { "virtual_alias_maps":
  value => "hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual_regexp"
}

Route mail to local users

postfix::virtual { "user@example.com":
  ensure      => present,
  destination => ['root', 'postmaster'],
}

Regex example

postfix::virtual { "/.+@.+/"
  ensure      => present,
  file        => '/etc/postfix/virtual_regexp',
  destination => 'root',
}

Route mail bound for ‘user@example.com’ to root.

postfix::virtual {'user@example.com':
    ensure      => present,
    destination => 'root',
}

Parameters:

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

    A string whose valid values are present or absent.

  • destination (Variant[String, Array[String]])

    A string defining where the e-mails will be delivered to, (virtual(8)). Example: ‘root`

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

    A string defining the location of the virtual map, pre hash. If not defined “$postfixpostfix::confdir/virtual” will be used as path. Example: ‘/etc/postfix/my_virtual_map`.

See Also:



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

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

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

  $dest_sets = [$destination].flatten.map |$i, $d| {
    $idx = $i+1
    "set \$entry/destination[${idx}] '${d}'"
  }

  case $ensure {
    'present': {
      $changes = [
        "defnode entry pattern[. = '${name}'] '${name}'",
        'rm $entry/destination',
        $dest_sets,
      ].flatten
    }

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

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

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

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

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