init.pp 3.69 KB
Newer Older
1
2
3
4
5
6
7
#
# == Class: postfix
#
# This class provides a basic setup of postfix with local and remote
# delivery and an SMTP server listening on the loopback interface.
#
# Parameters:
8
9
10
# - *$postfix_smtp_listen*: address on which the smtp service will listen to.
#      defaults to 127.0.0.1
# - *$root_mail_recipient*: who will recieve root's emails. defaults to 'nobody'
11
12
13
#
# Example usage:
#
14
15
#   node 'toto.example.com' {
#     $postfix_smtp_listen = '192.168.1.10'
16
17
18
19
20
21
#     include postfix
#   }
#
class postfix {

  # selinux labels differ from one distribution to another
22
  case $::operatingsystem {
23
24

    RedHat, CentOS: {
25
26
27
      case $::lsbmajdistrelease {
        '4':     { $postfix_seltype = 'etc_t' }
        '5','6': { $postfix_seltype = 'postfix_etc_t' }
28
29
30
31
32
33
34
35
36
37
        default: { $postfix_seltype = undef }
      }
    }

    default: {
      $postfix_seltype = undef
    }
  }

  # Default value for various options
38
39
  if $postfix_smtp_listen == '' {
    $postfix_smtp_listen = '127.0.0.1'
40
  }
41
42
  if $root_mail_recipient == '' {
    $root_mail_recipient = 'nobody'
43
  }
44
45
  if $postfix_use_amavisd == '' {
    $postfix_use_amavisd = 'no'
46
  }
47
48
  if $postfix_use_dovecot_lda == '' {
    $postfix_use_dovecot_lda = 'no'
49
  }
50
51
  if $postfix_use_schleuder == '' {
    $postfix_use_schleuder = 'no'
52
  }
53
54
  if $postfix_use_sympa == '' {
    $postfix_use_sympa = 'no'
55
  }
56
57
  if $postfix_mail_user == '' {
    $postfix_mail_user = 'vmail'
58
59
  }

60
61
62
63
64
  $mailx_package = $::lsbdistrelease ? {
    'squeeze' => 'bsd-mailx',
    'lucid'   => 'bsd-mailx',
    default   => 'mailx',
  }
65

66
67
68
  $master_os_template = $::operatingsystem ? {
    /RedHat|CentOS/          => 'postfix/master.cf.redhat.erb',
    /Debian|Ubuntu|kFreeBSD/ => 'postfix/master.cf.debian.erb',
69
70
  }

71
  package { 'postfix':
72
73
74
    ensure => installed,
  }

75
76
77
78
79
80
  package { 'mailx':
    ensure => installed,
    name   => $mailx_package,
  }

  service { 'postfix':
81
82
83
    ensure    => running,
    enable    => true,
    hasstatus => true,
84
85
    restart   => '/etc/init.d/postfix reload',
    require   => Package['postfix'],
86
87
  }

88
  file { '/etc/mailname':
89
    ensure  => present,
90
    content => "$::fqdn\n",
91
92
93
94
    seltype => $postfix_seltype,
  }

  # Aliases
95
96
97
  file { '/etc/aliases':
    ensure  => present,
    content => '# file managed by puppet\n',
98
99
    replace => false,
    seltype => $postfix_seltype,
100
    notify  => Exec['newaliases'],
101
102
103
  }

  # Aliases
104
105
  exec { 'newaliases':
    command     => '/usr/bin/newaliases',
106
    refreshonly => true,
107
108
    require     => Package['postfix'],
    subscribe   => File['/etc/aliases'],
109
110
111
  }

  # Config files
112
  file { '/etc/postfix/master.cf':
113
    ensure  => present,
114
115
116
117
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    content => $master_os_template,
118
    seltype => $postfix_seltype,
119
120
    notify  => Service['postfix'],
    require => Package['postfix'],
121
122
123
  }

  # Config files
124
  file { '/etc/postfix/main.cf':
125
    ensure  => present,
126
127
128
129
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    source  => 'puppet:///modules/postfix/main.cf',
130
131
    replace => false,
    seltype => $postfix_seltype,
132
133
    notify  => Service['postfix'],
    require => Package['postfix'],
134
135
136
137
  }

  # Default configuration parameters
  postfix::config {
138
139
140
    'myorigin':         value => $::fqdn;
    'alias_maps':       value => 'hash:/etc/aliases';
    'inet_interfaces':  value => 'all';
141
142
  }

143
  case $::operatingsystem {
144
145
    RedHat, CentOS: {
      postfix::config {
146
147
148
        'sendmail_path':    value => '/usr/sbin/sendmail.postfix';
        'newaliases_path':  value => '/usr/bin/newaliases.postfix';
        'mailq_path':       value => '/usr/bin/mailq.postfix';
149
150
      }
    }
151
    default: {}
152
153
  }

154
  mailalias {'root':
155
    recipient => $root_mail_recipient,
156
    notify    => Exec['newaliases'],
157
158
  }
}