changeset 302:01d1b0f6dbaf

Fix more IPv4 vs IPv6 settings Postfix wouldn't look up "localhost" but accepts IPs Checking for the existance of "ipaddress" covers us for now as a work-around, because IPv6-only doesn't have "ipaddress" but "IPv4 with IPv6 link-local" does have "ipaddress6"
author IBBoard <dev@ibboard.co.uk>
date Mon, 17 Feb 2020 19:45:46 +0000
parents 1bfc290270cc
children c16c977760c3
files manifests/templates.pp modules/postfix/manifests/init.pp modules/postfix/templates/main.cf.erb
diffstat 3 files changed, 20 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/manifests/templates.pp	Mon Feb 17 18:45:06 2020 +0000
+++ b/manifests/templates.pp	Mon Feb 17 19:45:46 2020 +0000
@@ -42,10 +42,14 @@
 	}
 
 	#VPS is a self-mastered Puppet machine, so bodge a Hosts file
+	if $primary_ip =~ Stdlib::IP::Address::V6 {
+		$lo_ip = '::1'
+	} else {
+		$lo_ip = '127.0.0.1'
+	}
 	file { '/etc/hosts':
 		ensure => present,
-		content => "127.0.0.1   localhost
-$primary_ip ${fqdn}",
+		content => "${lo_ip}   localhost\n${primary_ip} ${fqdn}",
 	}
 
 	require repos
@@ -706,7 +710,7 @@
 	){
 	class { 'postfix':
 		mailserver => $mailserver,
-		protocols  => 'ipv4',
+		protocols  => has_key($facts, 'ipaddress') ? { true => 'ipv4', default => 'ipv6' },
 	}
 	class { 'dovecot':
 		imapserver => $imapserver,
--- a/modules/postfix/manifests/init.pp	Mon Feb 17 18:45:06 2020 +0000
+++ b/modules/postfix/manifests/init.pp	Mon Feb 17 19:45:46 2020 +0000
@@ -2,6 +2,15 @@
   $mailserver,
   $protocols='all'
   ){
+
+  if has_key($facts, 'ipaddress') {
+    $lo_ip = '127.0.0.1'
+    $lo_networks = '127.0.0.0/8'
+  } else {
+    $lo_ip = '[::1]'
+    $lo_networks = '[::1]'
+  }
+  
   package { 'sendmail':
     ensure => 'absent',
   }
@@ -31,10 +40,7 @@
     content => template('postfix/main.cf.erb'),
   }
   file { '/etc/postfix/master.cf':
-    source => [
-      "puppet:///modules/postfix/master.${operatingsystem}${operatingsystemmajrelease}.cf",
-      'puppet:///modules/postfix/master.cf'
-    ]
+    content => template('postfix/master.cf.erb'),
   }
   #Hosted domains
   file { '/etc/postfix/vdomains':
--- a/modules/postfix/templates/main.cf.erb	Mon Feb 17 18:45:06 2020 +0000
+++ b/modules/postfix/templates/main.cf.erb	Mon Feb 17 19:45:46 2020 +0000
@@ -8,8 +8,9 @@
 inet_interfaces = all
 inet_protocols = <%= @protocols %>
 mydestination = $myhostname, localhost.$mydomain, localhost
+smtp_host_lookup = dns, native
 unknown_local_recipient_reject_code = 550
-mynetworks = 127.0.0.0/8
+mynetworks = <%= @lo_networks %>
 relay_domains = 
 alias_maps = hash:/etc/aliases
 alias_database = hash:/etc/aliases
@@ -86,4 +87,4 @@
 postscreen_access_list = permit_mynetworks, cidr:/etc/postfix/postscreen_access_private.cidr, cidr:/etc/postfix/postscreen_spf_whitelist.cidr
 postscreen_blacklist_action = enforce
 
-content_filter = smtp-amavis:[127.0.0.1]:10024
+content_filter = smtp-amavis:<%= @lo_ip %>:10024