diff --git a/manifests/init.pp b/manifests/init.pp index 9ca1b98..109b940 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,80 +1,103 @@ # == Class: postfix # # Manage postfix configuration with Debian preseeding # # === Parameters # # [*relayhost*] # Set the relayhost for the machine # # [*root_address*] # Set the forward address for mail sent to root. # Default: '' (keeping the current root alias) # # [*mailname*] # The default domain for outgoing mail # Default: $::fqdn # # [*destinations*] # Array of domains for whose the mail is locally delivered # Default: [$::fqdn] # # [*mynetworks*] # Array of networks from which to accept mail # Default: ['127.0.0.0/8', '[::ffff:127.0.0.0]/104', '[::1]/128'] (only accept local mail) +# +# [*relay_destinations*] +# Hash of destinations for relayed mail +# Default: {} (no relayed mail) +# Example: { +# 'forge.softwareheritage.org' => 'smtp:[tate.internal.softwareheritage.org]' +# } # === Examples # # class { 'postfix': # relayhost => '[smtp.example.com]', # } # # === Authors # # Nicolas Dandrimont # # === Copyright # # Copyright 2015 Nicolas Dandrimont # class postfix ( - $relayhost = undef, - $root_address = '', - $mailname = $::fqdn, - $destinations = [$::fqdn], - $mynetworks = ['127.0.0.0/8', '[::ffff:127.0.0.0]/104', '[::1]/128'], + $relayhost = undef, + $root_address = '', + $mailname = $::fqdn, + $destinations = [$::fqdn], + $mynetworks = ['127.0.0.0/8', '[::ffff:127.0.0.0]/104', '[::1]/128'], + $relay_destinations = {}, ){ validate_string($relayhost) validate_string($main_mailer_type) validate_string($root_address) validate_string($mailname) assert_type(Array[String], $destinations) assert_type(Array[String], $mynetworks) + assert_type(Hash[String, String], $transports) package {'postfix': ensure => present, } service {'postfix': - ensure => running, - enable => true, + ensure => running, + enable => true, require => [ File['/etc/postfix/main.cf'], File['/etc/postfix/master.cf'], + File['/etc/postfix/transport'], ], } file {'/etc/postfix/main.cf': ensure => present, content => template('postfix/main.cf.erb'), notify => Service['postfix'], require => Package['postfix'], } file {'/etc/postfix/master.cf': ensure => present, content => template('postfix/master.cf.erb'), notify => Service['postfix'], require => Package['postfix'], } + + file {'/etc/postfix/transport': + ensure => present, + content => template('postfix/transport.erb'), + notify => Exec['update transport'], + require => Package['postfix'], + } + + exec {'update transport': + path => ['/usr/bin', '/usr/sbin'], + command => 'postmap /etc/postfix/transport', + refreshonly => true, + } } diff --git a/templates/main.cf.erb b/templates/main.cf.erb index 807ce1a..7a8af9c 100644 --- a/templates/main.cf.erb +++ b/templates/main.cf.erb @@ -1,38 +1,40 @@ # Postfix main configuration file # # Managed by puppet - module swh-puppet # # Changes will be overwritten! smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = no # TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination myhostname = <%= @mailname %> alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = <%= @mailname %> mydestination = <%= @destinations.join(", ") %> relayhost = <%= @relayhost %> mynetworks = <%= @mynetworks.join(" ") %> mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all +relay_domains = <%= @relay_destinations.keys.join(", ") %> +transport_maps = hash:/etc/postfix/transport diff --git a/templates/transport.erb b/templates/transport.erb new file mode 100644 index 0000000..1e2246b --- /dev/null +++ b/templates/transport.erb @@ -0,0 +1,6 @@ +# Postfix transport map +# Managed by puppet, manual changes will be erased + +<% @relay_destinations.each do |domain, destination| -%> +<%= domain %> <%= destination %> +<% end -%>