hash.pp 1.99 KB
Newer Older
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
1
# == Definition: postfix::hash
2
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
3
4
5
# Creates postfix hashed "map" files. It will create "${name}", and then build
# "${name}.db" using the "postmap" command. The map file can then be referred to
# using postfix::config.
6
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
7
# === Parameters
8
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
9
10
11
# [*name*]   - the name of the map file.
# [*ensure*] - present/absent, defaults to present.
# [*source*] - file source.
12
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
13
# === Requires
14
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
15
# - Class["postfix"]
16
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
17
# === Examples
18
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
19
20
21
22
23
24
#   postfix::hash { '/etc/postfix/virtual':
#     ensure => present,
#   }
#   postfix::config { 'virtual_alias_maps':
#     value => 'hash:/etc/postfix/virtual',
#   }
25
#
26
27
28
29
30
31
define postfix::hash (
  $ensure='present',
  $source=undef,
  $content=undef,
) {
  include ::postfix::params
32

33
  validate_absolute_path($name)
34
35
36
37
#  validate_string($source)
#  validate_string($content)
  if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") }
  if !is_string($content) and !is_array($content) { fail("value for source should be either String type or Array type got ${content}") }
38
39
40
  validate_string($ensure)
  validate_re($ensure, ['present', 'absent'],
    "\$ensure must be either 'present' or 'absent', got '${ensure}'")
41

Raphaël Pinson's avatar
Raphaël Pinson committed
42
43
44
45
  if (!defined(Class['postfix'])) {
    fail 'You must define class postfix before using postfix::config!'
  }

46
  if $source and $content {
Wolf Noble's avatar
Wolf Noble committed
47
    fail 'You must provide either \'source\' or \'content\', not both'
48
49
  }

50
51
52
53
  File {
    mode    => '0600',
    owner   => root,
    group   => root,
54
    seltype => $postfix::params::seltype,
55
56
  }

57
58
59
60
61
  file { $name:
    ensure  => $ensure,
    source  => $source,
    content => $content,
    require => Package['postfix'],
62
63
64
65
  }

  file {"${name}.db":
    ensure  => $ensure,
66
    require => [File[$name], Exec["generate ${name}.db"]],
67
68
69
  }

  exec {"generate ${name}.db":
70
71
72
    command     => "postmap ${name}",
    #creates    => "${name}.db", # this prevents postmap from being run !
    subscribe   => File[$name],
73
    refreshonly => true,
74
  }
75
76

  Class['postfix'] -> Postfix::Hash[$title]
77
}