map.pp 2.35 KB
Newer Older
Adam Lewenberg's avatar
Adam Lewenberg committed
1
2
3
4
# Defines a Postfix map.  This handles installing the source file and running
# postmap or postalias as needed.  Example for a map file:
#
#     base::postfix::map { '/etc/postfix/access/smtp':
5
#       source => 'puppet:///modules/s_emailrouter/etc/postfix/access/smtp',
Adam Lewenberg's avatar
Adam Lewenberg committed
6
7
8
9
10
#     }
#
# Example for an aliases file, which has to use a different command:
#
#     base::postfix::map { '/etc/postfix/aliases':
11
12
#       command => 'postalias',
#       source  => 'puppet:///modules/s_nagios/etc/postfix/aliases',
Adam Lewenberg's avatar
Adam Lewenberg committed
13
14
15
16
17
18
19
20
21
22
23
#     }
#
# Either source or content can be used with the map.
#
# Currently does not correctly support any type other than btree or hash.
# Adding the other hash types wouldn't be hard, but would require dynamically
# determining the extension and (for dbm and sdbm) handling the creation of
# two files (*.pag and *.dir) instead of one.  So we'll wait until someone
# actually needs that.

define base::postfix::map(
24
25
26
27
28
  $ensure  = 'present',
  $command = 'postmap',
  $type    = 'hash',
  $content = undef,
  $source  = undef)
Adam Lewenberg's avatar
Adam Lewenberg committed
29
{
30
31
32
  if ($type != 'hash') and ($type != 'btree') {
    crit "unknown Postfix map type $type"
  }
Adam Lewenberg's avatar
Adam Lewenberg committed
33

34
35
36
37
38
39
40
  file { $name:
    ensure  => $ensure,
    content => $content,
    source  => $source,
    notify  => Exec["${command} ${type}:${name}"],
    require => Package['postfix'],
  }
Adam Lewenberg's avatar
Adam Lewenberg committed
41

42
43
44
45
46
47
48
49
50
51
52
  # If ensure is absent, remove the detritus of our hash.
  if ($ensure == 'absent') {
    file { "${name}.db": ensure => $ensure }
  } else {
    # We have to define two commands here.  The first uses creates and is
    # responsible for ensuring that the *.db file always exists (and is only
    # defined if the type is hash).  The second is called by notify and is
    # responsible for updating the hash when the source file changes.  We need
    # both because a command with a creates stanza won't run even if notified
    # if that file already exists.
    exec { "${command} ${type}:${name} initial":
53
      path    => '/bin:/usr/sbin:/usr/bin',
54
55
56
57
58
59
60
      command => "${command} ${type}:${name}",
      creates => "${name}.db",
      require => [ File[$name], File['/etc/postfix/main.cf'],
                   Package['postfix'] ],
    }
    exec { "${command} ${type}:${name}":
      refreshonly => true,
61
      path        => '/bin:/usr/sbin:/usr/bin',
62
63
      command     => "${command} ${type}:${name}",
      require     => [ File['/etc/postfix/main.cf'], Package['postfix'] ],
Adam Lewenberg's avatar
Adam Lewenberg committed
64
    }
65
66
  }
}