init.pp 4.07 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  case $::operatingsystem {
    /RedHat|CentOS|Fedora/: {
      $mailx_package = 'mailx'
    }

    /Debian|kFreeBSD/: {
      $mailx_package = $::lsbdistcodename ? {
        /lenny|etch|sarge/ => 'mailx',
        default            => 'bsd-mailx',
      }
    }

    'Ubuntu': {
      if (versioncmp('10', $::lsbmajdistrelease) > 0) {
        $mailx_package = 'mailx'
      } else {
        $mailx_package = 'bsd-mailx'
      }
    }
79
  }
80

81
  $master_os_template = $::operatingsystem ? {
82
83
    /RedHat|CentOS/          => template('postfix/master.cf.redhat.erb', 'postfix/master.cf.common.erb'),
    /Debian|Ubuntu|kFreeBSD/ => template('postfix/master.cf.debian.erb', 'postfix/master.cf.common.erb'),
84
85
  }

86
  package { 'postfix':
87
88
89
    ensure => installed,
  }

90
91
92
93
94
95
  package { 'mailx':
    ensure => installed,
    name   => $mailx_package,
  }

  service { 'postfix':
96
97
98
    ensure    => running,
    enable    => true,
    hasstatus => true,
99
100
    restart   => '/etc/init.d/postfix reload',
    require   => Package['postfix'],
101
102
  }

103
  file { '/etc/mailname':
104
    ensure  => present,
105
    content => "$::fqdn\n",
106
107
108
109
    seltype => $postfix_seltype,
  }

  # Aliases
110
111
112
  file { '/etc/aliases':
    ensure  => present,
    content => '# file managed by puppet\n',
113
114
    replace => false,
    seltype => $postfix_seltype,
115
    notify  => Exec['newaliases'],
116
117
118
  }

  # Aliases
119
120
  exec { 'newaliases':
    command     => '/usr/bin/newaliases',
121
    refreshonly => true,
122
123
    require     => Package['postfix'],
    subscribe   => File['/etc/aliases'],
124
125
126
  }

  # Config files
127
  file { '/etc/postfix/master.cf':
128
    ensure  => present,
129
130
131
132
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    content => $master_os_template,
133
    seltype => $postfix_seltype,
134
135
    notify  => Service['postfix'],
    require => Package['postfix'],
136
137
138
  }

  # Config files
139
  file { '/etc/postfix/main.cf':
140
    ensure  => present,
141
142
143
144
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    source  => 'puppet:///modules/postfix/main.cf',
145
146
    replace => false,
    seltype => $postfix_seltype,
147
148
    notify  => Service['postfix'],
    require => Package['postfix'],
149
150
151
152
  }

  # Default configuration parameters
  postfix::config {
153
154
155
    'myorigin':         value => $::fqdn;
    'alias_maps':       value => 'hash:/etc/aliases';
    'inet_interfaces':  value => 'all';
156
157
  }

158
  case $::operatingsystem {
159
160
    RedHat, CentOS: {
      postfix::config {
161
162
163
        'sendmail_path':    value => '/usr/sbin/sendmail.postfix';
        'newaliases_path':  value => '/usr/bin/newaliases.postfix';
        'mailq_path':       value => '/usr/bin/mailq.postfix';
164
165
      }
    }
166
    default: {}
167
168
  }

169
  mailalias {'root':
170
    recipient => $root_mail_recipient,
171
    notify    => Exec['newaliases'],
172
173
  }
}