Defined Type: postfix::lookup::database

Defined in:
vendor_modules/postfix/manifests/lookup/database.pp

Overview

Define lookup tables using static database files.

Examples:

Define a `transport(5)` table

postfix::lookup::database { '/etc/postfix/transport':
  content => @(EOS/L),
    example.com :
    | EOS
  type    => 'hash',
}

Manage the `aliases(5)` table with `mailalias` resources

postfix::lookup::database { '/etc/aliases':
  type => 'hash',
}
Mailalias <||> -> Postfix::Lookup::Database['/etc/aliases']

Parameters:

  • ensure (Enum['present', 'absent']) (defaults to: 'present')
  • path (Stdlib::Absolutepath) (defaults to: $title)
  • type (Postfix::Type::Lookup::Database) (defaults to: $postfix::default_database_type)
  • content (Optional[String]) (defaults to: undef)
  • source (Optional[String]) (defaults to: undef)
  • input_type (Enum['lookup', 'aliases']) (defaults to: 'lookup')

See Also:

Since:

  • 1.0.0



26
27
28
29
30
31
32
33
34
35
36
37
38
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'vendor_modules/postfix/manifests/lookup/database.pp', line 26

define postfix::lookup::database (
  Enum['present', 'absent']       $ensure      = 'present',
  Stdlib::Absolutepath            $path        = $title,
  Postfix::Type::Lookup::Database $type        = $postfix::default_database_type,
  Enum['lookup', 'aliases']       $input_type  = 'lookup',
  Optional[String]                $content     = undef,
  Optional[String]                $source      = undef,
) {

  include postfix

  if $content and $source {
    fail('Only one of $content or $source should be specified.')
  }

  $_ensure = $ensure ? {
    'absent' => 'absent',
    default  => 'file',
  }

  file { $path:
    ensure  => $_ensure,
    owner   => 0,
    group   => 0,
    mode    => '0644',
    content => $content,
    source  => $source,
  }

  # Changes to files that aren't hashed generally don't get picked up without
  # a reload so trigger one
  if $type =~ Postfix::Type::Lookup::Database::Flat {
    File[$path] ~> Class['postfix::service']
  }

  if $ensure != 'absent' and has_key($postfix::lookup_packages, $type) {
    $lookup_package = $postfix::lookup_packages[$type]
    ensure_packages([$lookup_package])
    Package[$lookup_package] -> File[$path]
  }

  if $type =~ Postfix::Type::Lookup::Database::Hashed {

    case $type {
      'btree', 'hash': {
        $files = ["${path}.db"]
      }
      'cdb': {
        $files = ["${path}.cdb"]
      }
      'dbm', 'sdbm': {
        $files = ["${path}.pag", "${path}.dir"]
      }
      'lmdb': {
        $files = ["${path}.lmdb"]
      }
      default: {
        # noop
      }
    }

    file { $files:
      ensure => $_ensure,
      before => Class['postfix::service'],
    }

    if $ensure != 'absent' {

      # The exec resource fires unless each target hashed file exists and the
      # mtime of each is greater than the mtime of the source file
      $unless = join($files.reduce([]) |$memo, $x| {
        $memo + ["[ -f ${x} ]", "[ $(stat -c '%Y' ${x}) -gt $(stat -c '%Y' ${path}) ]"]
      }, ' && ')

      case $input_type {
          'lookup': {
            $postcmd = 'postmap'
          }
          'aliases': {
            $postcmd = 'postalias'
          }
      }

      exec { "${postcmd} ${type}:${path}":
        path    => $::path,
        unless  => $unless,
        require => File[$path],
        before  => File[$files],
      }
    }
  }
}