Fail if we are not an MX and do not have set MX to the mail relays
[mirror/dsa-puppet.git] / modules / roles / manifests / mta.pp
1 # Every one of our hosts has an MTA
2 #
3 # @param type exim4 or postfix.  exim4 is our default MTA
4 # @param heavy receive email from the internet and thus do spam filtering etc
5 # @param mailrelay receive mail on other hosts' behalf.  implies heavy
6 class roles::mta(
7   Enum['exim4', 'postfix'] $type = 'exim4',
8   Boolean $heavy = false,
9   Boolean $mailrelay = false,
10 ) {
11   if $type == 'exim4' {
12     if $mailrelay {
13       include roles::mailrelay
14     } elsif $heavy {
15       include exim::mx
16     } else {
17       include exim
18     }
19   } elsif $type == 'postfix' {
20     if $mailrelay {
21       fail("Unsupported: mailrelay on type ${type}")
22     }
23     include postfix
24   } else {
25     fail("Unexpected mta type ${type}")
26   }
27
28
29   $mxdata = dig($deprecated::nodeinfo, 'ldap', 'mXRecord')
30   if $mxdata and $mxdata.any |$item| { $item =~ /INCOMING-MX/ } {
31     $mailport = lookup( { 'name' => 'exim::mail_port', 'default_value' => undef } )
32
33     @@concat::fragment { "manualroute-to-${::fqdn}":
34       tag     => 'exim::manualroute::to::mailrelay',
35       target  => '/etc/exim4/manualroute',
36       content => $mailport == undef ? {
37         true    => "${::fqdn}:   ${::fqdn}",
38         default => "${::fqdn}:   ${::fqdn}::${mailport}",
39       }
40     }
41
42     Ferm::Rule::Simple <<| tag == 'smtp::server::from::mailrelay' |>> {
43       port => $mailport == undef ? {
44         true    => 25,
45         default => $mailport,
46       }
47     }
48   } else {
49     if ! defined(Class['exim::mx']) and ! defined(Class['postfix']) {
50       fail('We are not an exim::mx (or a postfix) yet do not have set our MXs to INCOMING-MX.')
51     }
52   }
53 }