virtual.pp 1.76 KB
Newer Older
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
1
# == Definition: postfix::virtual
2
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
3
# Manages content of the /etc/postfix/virtual map.
4
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
5
# === Parameters
6
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
7
8
9
# [*name*]        - name of address postfix will lookup. See virtual(8).
# [*destination*] - where the emails will be delivered to. See virtual(8).
# [*ensure*]      - present/absent, defaults to present.
Erinn Looney-Triggs's avatar
Erinn Looney-Triggs committed
10
# [*file*]        - A string defining the location of the pre-hash map.
11
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
12
# === Requires
13
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
14
15
16
17
# - Class["postfix"]
# - Postfix::Hash["/etc/postfix/virtual"]
# - Postfix::Config["virtual_alias_maps"]
# - augeas
18
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
19
# === Examples
20
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#   node "toto.example.com" {
#
#     include postfix
#
#     postfix::hash { "/etc/postfix/virtual":
#       ensure => present,
#     }
#     postfix::config { "virtual_alias_maps":
#       value => "hash:/etc/postfix/virtual"
#     }
#     postfix::virtual { "user@example.com":
#       ensure      => present,
#       destination => "root",
#     }
#   }
36
#
37
38
39
40
41
define postfix::virtual (
  $destination,
  $file='/etc/postfix/virtual',
  $ensure='present'
) {
42
  include ::postfix::augeas
43

44
45
46
47
48
  validate_string($destination)
  validate_string($file)
  validate_absolute_path($file)
  validate_string($ensure)

49
50
  case $ensure {
    'present': {
51
52
53
54
55
      $changes = [
        "set pattern[. = '${name}'] '${name}'",
        # TODO: support more than one destination
        "set pattern[. = '${name}']/destination '${destination}'",
      ]
56
57
58
59
60
61
62
    }

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

    default: {
63
      fail "\$ensure must be either 'present' or 'absent', got '${ensure}'"
64
65
66
67
    }
  }

  augeas {"Postfix virtual - ${name}":
68
69
70
    incl    => $file,
    lens    => 'Postfix_Virtual.lns',
    changes => $changes,
71
72
73
74
    require => [
      Package['postfix'],
      Augeas::Lens['postfix_virtual'],
      ],
75
    notify  => Postfix::Hash[$file],
76
77
  }
}