Unverified Commit 2d1906b3 authored by Romain Tartière's avatar Romain Tartière Committed by GitHub
Browse files

Add FreeBSD support (#288)



* Do not hardcode /etc/postfix

In order to bring support for FreeBSD, do not use the hardcoded
/etc/postfix path for the directory containing Postfix configuration:
FreeBSD ports are installed with a /usr/local/ prefix (by default) so
the configuration files on FreeBSD are stored in the
/usr/local/etc/postfix directory.

* Add support for FreeBSD

* Make it possible to tune the "root" group

FreeBSD does not have a "root" group.  The corresponding group is named
"wheel".

Allow to setup a custom "root_group", and adjust FreeBSD configuration
to set it to "wheel".

* Adjust the test suite so that it pass on FreeBSD

* Do not depend on $postfix::* before including postfix

Some resources parameters depend on the value of variable from the
postfix class.  Ensure these values are substitued only after including
postfix.

* Move default values from hiera to init.pp

These values are system-dependent, but this helps seeing the usual
default value when genering references.

* Move $manage_mailname parameter

* Explicitely mark internal classes as private

* Remove redundant postfix::params inclusion
Co-authored-by: default avatarRaphaël Pinson <github+aem1eeshi1@raphink.net>
Co-authored-by: default avatarRaphaël Pinson <github+aem1eeshi1@raphink.net>
parent 460dc7ad
---
postfix::confdir: "/usr/local/etc/postfix"
postfix::manage_mailname: false
postfix::manage_mailx: false
postfix::root_group: "wheel"
postfix::params::master_os_template: "postfix/master.cf.FreeBSD.erb"
postfix::params::restart_cmd: "/usr/local/etc/rc.d/postfix reload"
...
...@@ -35,11 +35,14 @@ ...@@ -35,11 +35,14 @@
# #
define postfix::canonical ( define postfix::canonical (
$destination, $destination,
$file='/etc/postfix/canonical', $file=undef,
$ensure='present' $ensure='present'
) { ) {
include postfix
include ::postfix::augeas include ::postfix::augeas
$_file = pick($file, "${postfix::confdir}/canonical")
case $ensure { case $ensure {
'present': { 'present': {
$changes = [ $changes = [
...@@ -58,10 +61,10 @@ define postfix::canonical ( ...@@ -58,10 +61,10 @@ define postfix::canonical (
} }
augeas {"Postfix canonical - ${name}": augeas {"Postfix canonical - ${name}":
incl => $file, incl => $_file,
lens => 'Postfix_Canonical.lns', lens => 'Postfix_Canonical.lns',
changes => $changes, changes => $changes,
require => [Package['postfix'], Augeas::Lens['postfix_canonical']], require => [Package['postfix'], Augeas::Lens['postfix_canonical']],
notify => Exec["generate ${file}.db"], notify => Exec["generate ${_file}.db"],
} }
} }
...@@ -50,12 +50,14 @@ define postfix::conffile ( ...@@ -50,12 +50,14 @@ define postfix::conffile (
Enum['present', 'absent', 'directory'] $ensure = 'present', Enum['present', 'absent', 'directory'] $ensure = 'present',
Variant[Array[String], String, Undef] $source = undef, Variant[Array[String], String, Undef] $source = undef,
Optional[String] $content = undef, Optional[String] $content = undef,
Stdlib::Absolutepath $path = "/etc/postfix/${name}", Optional[Stdlib::Absolutepath] $path = undef,
String $mode = '0640', String $mode = '0640',
Hash $options = {}, Hash $options = {},
Boolean $show_diff = true, Boolean $show_diff = true,
) { ) {
include ::postfix::params include postfix
$_path = pick($path, "${postfix::confdir}/${name}")
if (!defined(Class['postfix'])) { if (!defined(Class['postfix'])) {
fail 'You must define class postfix before using postfix::config!' fail 'You must define class postfix before using postfix::config!'
...@@ -84,7 +86,7 @@ define postfix::conffile ( ...@@ -84,7 +86,7 @@ define postfix::conffile (
file { "postfix conffile ${name}": file { "postfix conffile ${name}":
ensure => $ensure, ensure => $ensure,
path => $path, path => $_path,
mode => $mode, mode => $mode,
owner => 'root', owner => 'root',
group => 'postfix', group => 'postfix',
......
...@@ -31,6 +31,7 @@ define postfix::config ( ...@@ -31,6 +31,7 @@ define postfix::config (
Optional[String] $value = undef, Optional[String] $value = undef,
Enum['present', 'absent', 'blank'] $ensure = 'present', Enum['present', 'absent', 'blank'] $ensure = 'present',
) { ) {
include postfix
if ($ensure == 'present') { if ($ensure == 'present') {
assert_type(Pattern[/^.+$/], $value) |$e, $a| { assert_type(Pattern[/^.+$/], $value) |$e, $a| {
...@@ -58,10 +59,10 @@ define postfix::config ( ...@@ -58,10 +59,10 @@ define postfix::config (
} }
augeas { "manage postfix '${title}'": augeas { "manage postfix '${title}'":
incl => '/etc/postfix/main.cf', incl => "${postfix::confdir}/main.cf",
lens => 'Postfix_Main.lns', lens => 'Postfix_Main.lns',
changes => $changes, changes => $changes,
require => File['/etc/postfix/main.cf'], require => File["${postfix::confdir}/main.cf"],
} }
Postfix::Config[$title] ~> Class['postfix::service'] Postfix::Config[$title] ~> Class['postfix::service']
......
class postfix::files { class postfix::files {
include ::postfix::params assert_private()
$alias_maps = $postfix::all_alias_maps $alias_maps = $postfix::all_alias_maps
$amavis_procs = $postfix::amavis_procs $amavis_procs = $postfix::amavis_procs
...@@ -18,6 +19,7 @@ class postfix::files { ...@@ -18,6 +19,7 @@ class postfix::files {
$master_bounce_command = $postfix::master_bounce_command $master_bounce_command = $postfix::master_bounce_command
$master_defer_command = $postfix::master_defer_command $master_defer_command = $postfix::master_defer_command
$myorigin = $postfix::myorigin $myorigin = $postfix::myorigin
$manage_mailname = $postfix::manage_mailname
$manage_aliases = $postfix::manage_aliases $manage_aliases = $postfix::manage_aliases
$manage_root_alias = $postfix::manage_root_alias $manage_root_alias = $postfix::manage_root_alias
$root_mail_recipient = $postfix::root_mail_recipient $root_mail_recipient = $postfix::root_mail_recipient
...@@ -41,11 +43,13 @@ class postfix::files { ...@@ -41,11 +43,13 @@ class postfix::files {
replace => $manage_conffiles, replace => $manage_conffiles,
} }
file { '/etc/mailname': if $manage_mailname {
ensure => 'file', file { '/etc/mailname':
content => "${::fqdn}\n", ensure => 'file',
mode => '0644', content => "${::fqdn}\n",
seltype => $postfix::params::seltype, mode => '0644',
seltype => $postfix::params::seltype,
}
} }
# Aliases # Aliases
...@@ -73,10 +77,10 @@ class postfix::files { ...@@ -73,10 +77,10 @@ class postfix::files {
) )
} }
file { '/etc/postfix/master.cf': file { "${postfix::confdir}/master.cf":
ensure => 'file', ensure => 'file',
content => $_mastercf_content, content => $_mastercf_content,
group => 'root', group => $postfix::root_group,
mode => '0644', mode => '0644',
owner => 'root', owner => 'root',
seltype => $postfix::params::seltype, seltype => $postfix::params::seltype,
...@@ -84,9 +88,9 @@ class postfix::files { ...@@ -84,9 +88,9 @@ class postfix::files {
} }
# Config files # Config files
file { '/etc/postfix/main.cf': file { "${postfix::confdir}/main.cf":
ensure => 'file', ensure => 'file',
group => 'root', group => $postfix::root_group,
mode => '0644', mode => '0644',
owner => 'root', owner => 'root',
replace => false, replace => false,
......
...@@ -93,6 +93,8 @@ ...@@ -93,6 +93,8 @@
# } # }
# #
class postfix ( class postfix (
Stdlib::Absolutepath $confdir = '/etc/postfix',
String $root_group = 'root',
String $alias_maps = 'hash:/etc/aliases', String $alias_maps = 'hash:/etc/aliases',
Optional[Hash] $configs = {}, Optional[Hash] $configs = {},
Integer $amavis_procs = 2, Integer $amavis_procs = 2,
...@@ -106,6 +108,7 @@ class postfix ( ...@@ -106,6 +108,7 @@ class postfix (
Boolean $mailman = false, Boolean $mailman = false,
String $maincf_source = "puppet:///modules/${module_name}/main.cf", String $maincf_source = "puppet:///modules/${module_name}/main.cf",
Boolean $manage_conffiles = true, Boolean $manage_conffiles = true,
Boolean $manage_mailname = true,
Boolean $manage_mailx = true, Boolean $manage_mailx = true,
Optional[String] $mastercf_source = undef, Optional[String] $mastercf_source = undef,
Optional[String] $mastercf_content = undef, Optional[String] $mastercf_content = undef,
...@@ -151,7 +154,7 @@ class postfix ( ...@@ -151,7 +154,7 @@ class postfix (
$all_alias_maps = $ldap ? { $all_alias_maps = $ldap ? {
false => $alias_maps, false => $alias_maps,
true => "${alias_maps}, ldap:/etc/postfix/ldap-aliases.cf", true => "${alias_maps}, ldap:${confdir}/ldap-aliases.cf",
} }
create_resources('::postfix::config', $configs) create_resources('::postfix::config', $configs)
......
...@@ -21,7 +21,7 @@ class postfix::ldap { ...@@ -21,7 +21,7 @@ class postfix::ldap {
if $::osfamily == 'Debian' { if $::osfamily == 'Debian' {
package {'postfix-ldap': package {'postfix-ldap':
before => File['/etc/postfix/ldap-aliases.cf'], before => File["${postfix::confdir}/ldap-aliases.cf"],
} }
} }
...@@ -39,7 +39,7 @@ class postfix::ldap { ...@@ -39,7 +39,7 @@ class postfix::ldap {
default => $postfix::ldap_options, default => $postfix::ldap_options,
} }
file {'/etc/postfix/ldap-aliases.cf': file {"${postfix::confdir}/ldap-aliases.cf":
ensure => 'file', ensure => 'file',
owner => 'root', owner => 'root',
group => 'postfix', group => 'postfix',
......
...@@ -12,21 +12,22 @@ ...@@ -12,21 +12,22 @@
# mailman => true, # mailman => true,
# } # }
class postfix::mailman { class postfix::mailman {
include postfix
postfix::config { postfix::config {
'virtual_alias_maps': 'virtual_alias_maps':
value => 'hash:/etc/postfix/virtual'; value => "hash:${postfix::confdir}/virtual";
'transport_maps': 'transport_maps':
value => 'hash:/etc/postfix/transport'; value => "hash:${postfix::confdir}/transport";
'mailman_destination_recipient_limit': 'mailman_destination_recipient_limit':
value => '1'; value => '1';
} }
postfix::hash { '/etc/postfix/virtual': postfix::hash { "${postfix::confdir}/virtual":
ensure => 'present', ensure => 'present',
} }
postfix::hash { '/etc/postfix/transport': postfix::hash { "${postfix::confdir}/transport":
ensure => 'present', ensure => 'present',
} }
......
...@@ -32,11 +32,14 @@ define postfix::map ( ...@@ -32,11 +32,14 @@ define postfix::map (
Variant[Array[String], String, Undef] $source = undef, Variant[Array[String], String, Undef] $source = undef,
Optional[Variant[Sensitive[String],String]] $content = undef, Optional[Variant[Sensitive[String],String]] $content = undef,
String $type = 'hash', String $type = 'hash',
Stdlib::Absolutepath $path = "/etc/postfix/${name}", Optional[Stdlib::Absolutepath] $path = undef,
String[4,4] $mode = '0640' String[4,4] $mode = '0640'
) { ) {
include postfix
include ::postfix::params include ::postfix::params
$_path = pick($path, "${postfix::confdir}/${name}")
if (!defined(Class['postfix'])) { if (!defined(Class['postfix'])) {
fail 'You must define class postfix before using postfix::config!' fail 'You must define class postfix before using postfix::config!'
} }
...@@ -58,7 +61,7 @@ define postfix::map ( ...@@ -58,7 +61,7 @@ define postfix::map (
file { "postfix map ${name}": file { "postfix map ${name}":
ensure => $ensure, ensure => $ensure,
path => $path, path => $_path,
source => $source, source => $source,
content => $content, content => $content,
owner => 'root', owner => 'root',
...@@ -71,7 +74,7 @@ define postfix::map ( ...@@ -71,7 +74,7 @@ define postfix::map (
if $type !~ /^(cidr|pcre)$/ { if $type !~ /^(cidr|pcre)$/ {
file {"postfix map ${name}.db": file {"postfix map ${name}.db":
ensure => $ensure, ensure => $ensure,
path => "${path}.db", path => "${_path}.db",
owner => 'root', owner => 'root',
group => 'postfix', group => 'postfix',
mode => $mode, mode => $mode,
...@@ -81,8 +84,8 @@ define postfix::map ( ...@@ -81,8 +84,8 @@ define postfix::map (
} }
$generate_cmd = $ensure ? { $generate_cmd = $ensure ? {
'absent' => "rm ${path}.db", 'absent' => "rm ${_path}.db",
'present' => "postmap ${path}", 'present' => "postmap ${_path}",
} }
exec {"generate ${name}.db": exec {"generate ${name}.db":
......
...@@ -26,36 +26,41 @@ ...@@ -26,36 +26,41 @@
# } # }
# #
class postfix::mta ( class postfix::mta (
Pattern[/^\S+(?:,\s*\S+)*$/] $mydestination = $postfix::mydestination, Optional[Pattern[/^\S+(?:,\s*\S+)*$/]] $mydestination = undef,
Pattern[/^(?:\S+?(?:(?:,\s+)|(?:\s+))?)*$/] $mynetworks = $postfix::mynetworks, Optional[Pattern[/^(?:\S+?(?:(?:,\s+)|(?:\s+))?)*$/]] $mynetworks = undef,
Pattern[/^\S+$/] $relayhost = $postfix::relayhost, Optional[Pattern[/^\S+$/]] $relayhost = undef,
) { ) {
include postfix
$_mydestination = pick($mydestination, $postfix::mydestination)
$_mynetworks = pick($mynetworks, $postfix::mynetworks)
$_relayhost = pick($relayhost, $postfix::relayhost)
# If direct is specified then relayhost should be blank # If direct is specified then relayhost should be blank
if ($relayhost == 'direct') { if ($_relayhost == 'direct') {
postfix::config { 'relayhost': ensure => 'blank' } postfix::config { 'relayhost': ensure => 'blank' }
} }
else { else {
postfix::config { 'relayhost': value => $relayhost } postfix::config { 'relayhost': value => $_relayhost }
} }
if ($mydestination == 'blank') { if ($_mydestination == 'blank') {
postfix::config { 'mydestination': ensure => 'blank' } postfix::config { 'mydestination': ensure => 'blank' }
} else { } else {
postfix::config { 'mydestination': value => $mydestination } postfix::config { 'mydestination': value => $_mydestination }
} }
postfix::config { postfix::config {
'mynetworks': value => $mynetworks; 'mynetworks': value => $_mynetworks;
'virtual_alias_maps': value => 'hash:/etc/postfix/virtual'; 'virtual_alias_maps': value => "hash:${postfix::confdir}/virtual";
'transport_maps': value => 'hash:/etc/postfix/transport'; 'transport_maps': value => "hash:${postfix::confdir}/transport";
} }
postfix::hash { '/etc/postfix/virtual': postfix::hash { "${postfix::confdir}/virtual":
ensure => 'present', ensure => 'present',
} }
postfix::hash { '/etc/postfix/transport': postfix::hash { "${postfix::confdir}/transport":
ensure => 'present', ensure => 'present',
} }
......
class postfix::packages { class postfix::packages {
include ::postfix::params assert_private()
package { 'postfix': package { 'postfix':
ensure => $postfix::postfix_ensure, ensure => $postfix::postfix_ensure,
......
...@@ -23,17 +23,22 @@ ...@@ -23,17 +23,22 @@
# } # }
# #
class postfix::satellite ( class postfix::satellite (
$mydestination = $postfix::mydestination, $mydestination = undef,
$mynetworks = $postfix::mynetworks, $mynetworks = undef,
$relayhost = $postfix::relayhost, $relayhost = undef,
) { ) {
include postfix
assert_type(Pattern[/^\S+$/], $postfix::myorigin) assert_type(Pattern[/^\S+$/], $postfix::myorigin)
$_mydestination = pick($mydestination, $postfix::mydestination)
$_mynetworks = pick($mynetworks, $postfix::mynetworks)
$_relayhost = pick($relayhost, $postfix::relayhost)
class { '::postfix::mta': class { '::postfix::mta':
mydestination => $mydestination, mydestination => $_mydestination,
mynetworks => $mynetworks, mynetworks => $_mynetworks,
relayhost => $relayhost, relayhost => $_relayhost,
} }
postfix::virtual { "@${postfix::myorigin}": postfix::virtual { "@${postfix::myorigin}":
......
class postfix::service { class postfix::service {
assert_private()
$manage_aliases = $postfix::manage_aliases $manage_aliases = $postfix::manage_aliases
......
...@@ -44,11 +44,14 @@ ...@@ -44,11 +44,14 @@
define postfix::transport ( define postfix::transport (
Optional[String] $destination = undef, Optional[String] $destination = undef,
Optional[String] $nexthop=undef, Optional[String] $nexthop=undef,
Stdlib::Absolutepath $file='/etc/postfix/transport', Optional[Stdlib::Absolutepath] $file=undef,
Enum['present', 'absent'] $ensure='present' Enum['present', 'absent'] $ensure='present'
) { ) {
include postfix
include ::postfix::augeas include ::postfix::augeas
$_file = pick($file, "${postfix::confdir}/transport")
$smtp_nexthop = (String($nexthop) =~ /\[.*\]/) $smtp_nexthop = (String($nexthop) =~ /\[.*\]/)
case $ensure { case $ensure {
...@@ -104,7 +107,7 @@ define postfix::transport ( ...@@ -104,7 +107,7 @@ define postfix::transport (
augeas {"Postfix transport - ${name}": augeas {"Postfix transport - ${name}":
lens => 'Postfix_Transport.lns', lens => 'Postfix_Transport.lns',
incl => $file, incl => $_file,
changes => $changes, changes => $changes,
require => Augeas::Lens['postfix_transport'], require => Augeas::Lens['postfix_transport'],
} }
...@@ -113,7 +116,7 @@ define postfix::transport ( ...@@ -113,7 +116,7 @@ define postfix::transport (
Package['postfix'] -> Postfix::Transport[$title] Package['postfix'] -> Postfix::Transport[$title]
} }
if defined(Postfix::Hash[$file]) { if defined(Postfix::Hash[$_file]) {
Postfix::Transport[$title] ~> Postfix::Hash[$file] Postfix::Transport[$title] ~> Postfix::Hash[$_file]
} }
} }
...@@ -40,11 +40,14 @@ ...@@ -40,11 +40,14 @@
define postfix::virtual ( define postfix::virtual (
Variant[String, Array[String]] $destination, Variant[String, Array[String]] $destination,
Stdlib::Absolutepath $file='/etc/postfix/virtual', Optional[Stdlib::Absolutepath] $file=undef,
Enum['present', 'absent'] $ensure='present' Enum['present', 'absent'] $ensure='present'
) { ) {
include postfix
include ::postfix::augeas include ::postfix::augeas
$_file = pick($file, "${postfix::confdir}/virtual")
$dest_sets = [$destination].flatten.map |$i, $d| { $dest_sets = [$destination].flatten.map |$i, $d| {
$idx = $i+1 $idx = $i+1
"set \$entry/destination[${idx}] '${d}'" "set \$entry/destination[${idx}] '${d}'"
...@@ -69,7 +72,7 @@ define postfix::virtual ( ...@@ -69,7 +72,7 @@ define postfix::virtual (
} }
augeas {"Postfix virtual - ${name}": augeas {"Postfix virtual - ${name}":
incl => $file, incl => $_file,
lens => 'Postfix_Virtual.lns', lens => 'Postfix_Virtual.lns',
changes => $changes, changes => $changes,
require => Augeas::Lens['postfix_virtual'], require => Augeas::Lens['postfix_virtual'],
...@@ -79,7 +82,7 @@ define postfix::virtual ( ...@@ -79,7 +82,7 @@ define postfix::virtual (
Package['postfix'] -> Postfix::Virtual[$title] Package['postfix'] -> Postfix::Virtual[$title]
} }
if defined(Postfix::Hash[$file]) { if defined(Postfix::Hash[$_file]) {
Postfix::Virtual[$title] ~> Postfix::Hash[$file] Postfix::Virtual[$title] ~> Postfix::Hash[$_file]
} }
} }