diff options
Diffstat (limited to 'manifests')
-rw-r--r-- | manifests/classes/postfix-mailman.pp | 20 | ||||
-rw-r--r-- | manifests/classes/postfix-mta.pp | 56 | ||||
-rw-r--r-- | manifests/classes/postfix-satellite.pp | 35 | ||||
-rw-r--r-- | manifests/classes/postfix.pp | 91 | ||||
-rw-r--r-- | manifests/definitions/config.pp | 18 | ||||
-rw-r--r-- | manifests/definitions/hash.pp | 19 | ||||
-rw-r--r-- | manifests/definitions/transport.pp | 8 | ||||
-rw-r--r-- | manifests/definitions/virtual.pp | 8 | ||||
-rw-r--r-- | manifests/init.pp | 2 |
9 files changed, 257 insertions, 0 deletions
diff --git a/manifests/classes/postfix-mailman.pp b/manifests/classes/postfix-mailman.pp new file mode 100644 index 0000000..6a34f45 --- /dev/null +++ b/manifests/classes/postfix-mailman.pp @@ -0,0 +1,20 @@ +class postfix-ng::mailman { + $postfix_ng_smtp_listen = "0.0.0.0" + include postfix-ng + + postfix-ng::config { + "mydestination": value => ""; + "virtual_alias_maps": value => "hash:/etc/postfix/virtual"; + "transport_maps": value => "hash:/etc/postfix/transport"; + "mailman_destination_recipient_limit": value => "1", nonstandard => true; + } + + postfix-ng::hash { "/etc/postfix/virtual": + ensure => present, + } + + postfix-ng::hash { "/etc/postfix/transport": + ensure => present, + } + +} diff --git a/manifests/classes/postfix-mta.pp b/manifests/classes/postfix-mta.pp new file mode 100644 index 0000000..94f9f78 --- /dev/null +++ b/manifests/classes/postfix-mta.pp @@ -0,0 +1,56 @@ +######################################################################### +# +# This class configures a minimal MTA, listening on +# $postfix_ng_smtp_listen (default to localhost) and delivering mail to +# $postfix_mydestination (default to $fqdn). +# +# A valid relay host is required ($postfix_relayhost) for outbound email. +# +# transport & virtual maps get configured and can be populated with +# postfix-ng::transport and postfix-ng::virtual +# +# Example: +# +# node "toto.example.com" { +# $postfix_relayhost = "mail.example.com" +# $postfix_ng_smtp_listen = "0.0.0.0" +# $postfix_mydestination = "\$myorigin, myapp.example.com" +# +# include postfix-ng::mta +# +# postfix-ng::transport { "myapp.example.com": +# ensure => present, +# destination => "local:", +# } +# } +# + +class postfix-ng::mta { + + case $postfix_relayhost { + "": { fail("Required \$postfix_relayhost variable is not defined.") } + } + + case $postfix_mydestination { + "": { $postfix_mydestination = "\$myorigin" } + } + + include postfix-ng + + postfix-ng::config { + "mydestination": value => $postfix_mydestination; + "mynetworks": value => "127.0.0.0/8"; + "relayhost": value => $postfix_relayhost; + "virtual_alias_maps": value => "hash:/etc/postfix/virtual"; + "transport_maps": value => "hash:/etc/postfix/transport"; + } + + postfix-ng::hash { "/etc/postfix/virtual": + ensure => present, + } + + postfix-ng::hash { "/etc/postfix/transport": + ensure => present, + } + +} diff --git a/manifests/classes/postfix-satellite.pp b/manifests/classes/postfix-satellite.pp new file mode 100644 index 0000000..0f8cd5f --- /dev/null +++ b/manifests/classes/postfix-satellite.pp @@ -0,0 +1,35 @@ +######################################################################### +# +# This class configures all local email (cron, mdadm, etc) to be forwarded +# to $root_mail_recipient, using $postfix_relayhost as a relay. +# +# $valid_fqdn can be set to override $fqdn in the case where the FQDN is +# not recognized as valid by the destination server. +# +# All other parameters for postfix-ng::mta are valid. +# +# Example: +# +# node "toto.local.lan" { +# $postfix_relayhost = "mail.example.com" +# $valid_fqdn = "toto.example.com" +# $root_mail_recipient = "the.sysadmin@example.com" +# +# include postfix-ng::satellite +# } + +class postfix-ng::satellite { + + # If $fake_fqdn exists, use it to override $fqdn + case $valid_fqdn { + "": { $valid_fqdn = $fqdn } + default: { $fqdn = "${valid_fqdn}" } + } + + include postfix-ng::mta + + postfix-ng::virtual {"@${valid_fqdn}": + ensure => present, + destination => "root", + } +} diff --git a/manifests/classes/postfix.pp b/manifests/classes/postfix.pp new file mode 100644 index 0000000..f943a4e --- /dev/null +++ b/manifests/classes/postfix.pp @@ -0,0 +1,91 @@ +######################################################################### +# +# This class provides a basic setup of postfix with local and remote +# delivery and an SMTP server listening on the loopback interface. +# + +class postfix-ng { + + # Default value for various options + case $postfix_ng_smtp_listen { + "": { $postfix_ng_smtp_listen = "127.0.0.1" } + } + 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", + } + + # Aliases + + file { "/etc/aliases": + ensure => present, + content => "# file managed by puppet\n", + replace => false, + notify => Exec["newaliases"], + } + + exec { "newaliases": + command => "/usr/bin/newaliases", + refreshonly => true, + require => Package["postfix"], + subscribe => File["/etc/aliases"], + } + + # Config files + + file { "/etc/postfix/master.cf": + ensure => present, + content => $lsbdistcodename ? { + Tikanga => template("postfix-ng/master.cf.redhat5.erb"), + etch => template("postfix-ng/master.cf.debian-etch.erb"), + default => "No puppet template defined for $lsbdistcodename\n", + }, + notify => Service["postfix"], + require => Package["postfix"], + } + + file { "/etc/postfix/main.cf": + ensure => present, + source => "puppet:///postfix-ng/main.cf", + replace => false, + notify => Service["postfix"], + require => Package["postfix"], + } + + # Default configuration parameters + + postfix-ng::config { + "myorigin": value => "${fqdn}"; + "alias_maps": value => "hash:/etc/aliases"; + "inet_interfaces": value => "all"; + } + + case $operatingsystem { + RedHat: { + postfix-ng::config { + "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"], + } +} diff --git a/manifests/definitions/config.pp b/manifests/definitions/config.pp new file mode 100644 index 0000000..ec6c782 --- /dev/null +++ b/manifests/definitions/config.pp @@ -0,0 +1,18 @@ +define postfix-ng::config ($ensure = present, $value, $nonstandard = false) { + case $ensure { + present: { + exec {"postconf -e ${name}='${value}'": + unless => $nonstandard ? { + false => "test \"x$(postconf -h ${name})\" == 'x${value}'", + true => "test \"x$(egrep '^${name} ' /etc/postfix/main.cf | cut -d= -f2 | cut -d' ' -f2)\" == 'x${value}'", + }, + notify => Service["postfix"], + require => File["/etc/postfix/main.cf"], + } + } + + absent: { + fail "postfix-ng::config ensure => absent: Not implemented" + } + } +} diff --git a/manifests/definitions/hash.pp b/manifests/definitions/hash.pp new file mode 100644 index 0000000..f21e270 --- /dev/null +++ b/manifests/definitions/hash.pp @@ -0,0 +1,19 @@ +define postfix-ng::hash ($ensure) { + file {"${name}": + ensure => $ensure, + mode => 600, + } + + file {"${name}.db": + ensure => $ensure, + mode => 600, + require => [File["${name}"], Exec["generate ${name}.db"]], + } + + exec {"generate ${name}.db": + command => "postmap ${name}", + #creates => "${name}.db", # this prevents postmap from being run ! + subscribe => File["${name}"], + refreshonly => true + } +} diff --git a/manifests/definitions/transport.pp b/manifests/definitions/transport.pp new file mode 100644 index 0000000..ea23bf6 --- /dev/null +++ b/manifests/definitions/transport.pp @@ -0,0 +1,8 @@ +define postfix-ng::transport ($ensure, $destination) { + line {"${name} ${destination}": + ensure => present, + file => "/etc/postfix/transport", + line => "${name} ${destination}", + notify => Exec["generate /etc/postfix/transport.db"], + } +} diff --git a/manifests/definitions/virtual.pp b/manifests/definitions/virtual.pp new file mode 100644 index 0000000..950107c --- /dev/null +++ b/manifests/definitions/virtual.pp @@ -0,0 +1,8 @@ +define postfix-ng::virtual ($ensure, $destination) { + line {"${name} ${destination}": + ensure => present, + file => "/etc/postfix/virtual", + line => "${name} ${destination}", + notify => Exec["generate /etc/postfix/virtual.db"], + } +} diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..6cc1969 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,2 @@ +import "classes/*.pp" +import "definitions/*.pp" |