postfix.pp 3.07 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
8
9
10
11
12
13
14
15
16
17
# Parameters:
# - *$postfix_ng_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"
#
# Example usage:
#
#   node "toto.example.com" {
#     $postfix_ng_smtp_listen = "192.168.1.10"
#     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
26
27
28
29
30
31
32
33
34
35
      case $lsbmajdistrelease {
        "4":     { $postfix_seltype = "etc_t" }
        "5":     { $postfix_seltype = "postfix_etc_t" }
        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
45
46
47
48
49
50
51
52
53
54
55
56
  }
  case $root_mail_recipient {
    "":   { $root_mail_recipient = "nobody" }
  }


  package { ["postfix", "mailx"]:
    ensure => installed
  }

  service { "postfix":
    ensure  => running,
    require => Package["postfix"],
  }

  file { "/etc/mailname":
    ensure  => present,
    content => "${fqdn}\n",
57
    seltype => $postfix_seltype,
58
59
60
61
62
63
64
  }

  # Aliases
  file { "/etc/aliases":
    ensure => present,
    content => "# file managed by puppet\n",
    replace => false,
65
    seltype => $postfix_seltype,
66
67
68
    notify => Exec["newaliases"],
  }

69
  # Aliases
70
71
72
73
74
75
76
77
78
79
  exec { "newaliases":
    command     => "/usr/bin/newaliases",
    refreshonly => true,
    require     => Package["postfix"],
    subscribe   => File["/etc/aliases"],
  }

  # Config files
  file { "/etc/postfix/master.cf":
    ensure  => present,
80
    owner => "root",
81
    group => "root",
82
    mode => "0644",
83
84
    content => $operatingsystem ? {
      Redhat => template("postfix/master.cf.redhat5.erb"),
85
      CentOS => template("postfix/master.cf.redhat5.erb"),
86
      Debian => template("postfix/master.cf.debian-etch.erb"),
87
      Ubuntu => template("postfix/master.cf.debian-etch.erb"),
88
    },
89
    seltype => $postfix_seltype,
90
91
92
93
    notify  => Service["postfix"],
    require => Package["postfix"],
  }

94
  # Config files
95
96
  file { "/etc/postfix/main.cf":
    ensure  => present,
97
    owner => "root",
98
    group => "root",
99
    mode => "0644",
Silvio Rhatto's avatar
Silvio Rhatto committed
100
    source  => "puppet:///modules/postfix/main.cf",
101
    replace => false,
102
    seltype => $postfix_seltype,
103
104
105
106
107
    notify  => Service["postfix"],
    require => Package["postfix"],
  }

  # Default configuration parameters
Francois Deppierraz's avatar
Francois Deppierraz committed
108
  postfix::config {
109
110
111
112
113
114
    "myorigin":   value => "${fqdn}";
    "alias_maps": value => "hash:/etc/aliases";
    "inet_interfaces": value => "all";
  }

  case $operatingsystem {
115
    RedHat, CentOS: {
Francois Deppierraz's avatar
Francois Deppierraz committed
116
      postfix::config {
117
118
119
120
121
122
123
124
125
126
127
128
        "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"],
  }
}