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

20
  # selinux labels differ from one distribution to another
21
22
  case $operatingsystem {

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

    default: {
      $postfix_seltype = undef
    }
  }

36
  # Default value for various options
37
38
  case $postfix_smtp_listen {
    "": { $postfix_smtp_listen = "127.0.0.1" }
39
40
41
42
43
44
  }
  case $root_mail_recipient {
    "":   { $root_mail_recipient = "nobody" }
  }


45
  package { "postfix":
46
47
48
    ensure => installed
  }

49
50
51
52
  package { "mailx":
    ensure => installed,
    name   => $lsbdistcodename ? {
      "squeeze" => "bsd-mailx",
53
      "lucid"   => "bsd-mailx",
54
55
56
57
      default   => "mailx",
    },
  }

58
59
60
61
62
63
64
65
  service { "postfix":
    ensure  => running,
    require => Package["postfix"],
  }

  file { "/etc/mailname":
    ensure  => present,
    content => "${fqdn}\n",
66
    seltype => $postfix_seltype,
67
68
69
70
71
72
73
  }

  # Aliases
  file { "/etc/aliases":
    ensure => present,
    content => "# file managed by puppet\n",
    replace => false,
74
    seltype => $postfix_seltype,
75
76
77
    notify => Exec["newaliases"],
  }

78
  # Aliases
79
80
81
82
83
84
85
86
87
88
  exec { "newaliases":
    command     => "/usr/bin/newaliases",
    refreshonly => true,
    require     => Package["postfix"],
    subscribe   => File["/etc/aliases"],
  }

  # Config files
  file { "/etc/postfix/master.cf":
    ensure  => present,
89
    owner => "root",
90
    group => "root",
91
    mode => "0644",
92
    content => $operatingsystem ? {
93
      /RedHat|CentOS/ => template("postfix/master.cf.redhat.erb", "postfix/master.cf.common.erb"),
94
      /Debian|Ubuntu|kFreeBSD/ => template("postfix/master.cf.debian.erb", "postfix/master.cf.common.erb"),
95
    },
96
    seltype => $postfix_seltype,
97
98
99
100
    notify  => Service["postfix"],
    require => Package["postfix"],
  }

101
  # Config files
102
103
  file { "/etc/postfix/main.cf":
    ensure  => present,
104
    owner => "root",
105
    group => "root",
106
    mode => "0644",
Silvio Rhatto's avatar
Silvio Rhatto committed
107
    source  => "puppet:///modules/postfix/main.cf",
108
    replace => false,
109
    seltype => $postfix_seltype,
110
111
112
113
114
    notify  => Service["postfix"],
    require => Package["postfix"],
  }

  # Default configuration parameters
Francois Deppierraz's avatar
Francois Deppierraz committed
115
  postfix::config {
116
117
118
119
120
121
    "myorigin":   value => "${fqdn}";
    "alias_maps": value => "hash:/etc/aliases";
    "inet_interfaces": value => "all";
  }

  case $operatingsystem {
122
    RedHat, CentOS: {
Francois Deppierraz's avatar
Francois Deppierraz committed
123
      postfix::config {
124
125
126
127
128
129
130
131
132
133
134
135
        "sendmail_path": value => "/usr/sbin/sendmail.postfix";
        "newaliases_path": value => "/usr/bin/newaliases.postfix";
        "mailq_path": value => "/usr/bin/mailq.postfix";
      }
    }
  }

  mailalias {"root":
    recipient => $root_mail_recipient,
    notify    => Exec["newaliases"],
  }
}