config.pp 1.15 KB
Newer Older
1
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
2
# == Definition: postfix::config
3
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
4
# Uses Augeas to add/alter/remove options in postfix main
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
5
# configuation file (/etc/postfix/main.cf).
6
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
7
8
# TODO: make this a type with an Augeas and a postconf providers.
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
9
# === Parameters
10
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
11
12
13
# [*name*]   - name of the parameter.
# [*ensure*] - present/absent. defaults to present.
# [*value*]  - value of the parameter.
14
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
15
# === Requires
16
#
Raphaël Pinson's avatar
Doc    
Raphaël Pinson committed
17
# - Class["postfix"]
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
#   postfix::config { 'smtp_use_tls':
#     ensure => 'present',
#     value  => 'yes',
#   }
25
26
#
define postfix::config ($value, $ensure = present) {
27

Raphaël Pinson's avatar
Raphaël Pinson committed
28
29
30
31
32
  validate_string($value)
  validate_string($ensure)
  validate_re($ensure, ['present', 'absent'],
    "\$ensure must be either 'present' or 'absent', got '${ensure}'")

33
  Augeas {
34
35
    incl    => '/etc/postfix/main.cf',
    lens    => 'Postfix_Main.lns',
36
37
    notify  => Service['postfix'],
    require => File['/etc/postfix/main.cf'],
38
39
  }

40
41
  case $ensure {
    present: {
fredj's avatar
fredj committed
42
      augeas { "set postfix '${name}' to '${value}'":
Raphaël Pinson's avatar
Linting    
Raphaël Pinson committed
43
        changes => "set ${name} '${value}'",
44
45
46
      }
    }
    absent: {
fredj's avatar
fredj committed
47
      augeas { "rm postfix '${name}'":
Raphaël Pinson's avatar
Linting    
Raphaël Pinson committed
48
        changes => "rm ${name}",
49
      }
50
    }
51
    default: {}
52
53
  }
}