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
Loading
Loading
Loading
Loading

data/os/FreeBSD.yaml

0 → 100644
+8 −0
Original line number Diff line number Diff line
---
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"
...
+6 −3
Original line number Diff line number Diff line
@@ -35,11 +35,14 @@
#
define postfix::canonical (
  $destination,
  $file='/etc/postfix/canonical',
  $file=undef,
  $ensure='present'
) {
  include postfix
  include ::postfix::augeas

  $_file = pick($file, "${postfix::confdir}/canonical")

  case $ensure {
    'present': {
      $changes = [
@@ -58,10 +61,10 @@ define postfix::canonical (
  }

  augeas {"Postfix canonical - ${name}":
    incl    => $file,
    incl    => $_file,
    lens    => 'Postfix_Canonical.lns',
    changes => $changes,
    require => [Package['postfix'], Augeas::Lens['postfix_canonical']],
    notify  => Exec["generate ${file}.db"],
    notify  => Exec["generate ${_file}.db"],
  }
}
+5 −3
Original line number Diff line number Diff line
@@ -50,12 +50,14 @@ define postfix::conffile (
  Enum['present', 'absent', 'directory'] $ensure    = 'present',
  Variant[Array[String], String, Undef]  $source    = undef,
  Optional[String]                       $content   = undef,
  Stdlib::Absolutepath                   $path      = "/etc/postfix/${name}",
  Optional[Stdlib::Absolutepath]         $path      = undef,
  String                                 $mode      = '0640',
  Hash                                   $options   = {},
  Boolean                                $show_diff = true,
) {
  include ::postfix::params
  include postfix

  $_path = pick($path, "${postfix::confdir}/${name}")

  if (!defined(Class['postfix'])) {
    fail 'You must define class postfix before using postfix::config!'
@@ -84,7 +86,7 @@ define postfix::conffile (

  file { "postfix conffile ${name}":
    ensure    => $ensure,
    path      => $path,
    path      => $_path,
    mode      => $mode,
    owner     => 'root',
    group     => 'postfix',
+3 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ define postfix::config (
  Optional[String]                   $value  = undef,
  Enum['present', 'absent', 'blank'] $ensure = 'present',
) {
  include postfix

  if ($ensure == 'present') {
    assert_type(Pattern[/^.+$/], $value) |$e, $a| {
@@ -58,10 +59,10 @@ define postfix::config (
  }

  augeas { "manage postfix '${title}'":
    incl    => '/etc/postfix/main.cf',
    incl    => "${postfix::confdir}/main.cf",
    lens    => 'Postfix_Main.lns',
    changes => $changes,
    require => File['/etc/postfix/main.cf'],
    require => File["${postfix::confdir}/main.cf"],
  }

  Postfix::Config[$title] ~> Class['postfix::service']
+9 −5
Original line number Diff line number Diff line
class postfix::files {
  include ::postfix::params
  assert_private()


  $alias_maps          = $postfix::all_alias_maps
  $amavis_procs        = $postfix::amavis_procs
@@ -18,6 +19,7 @@ class postfix::files {
  $master_bounce_command = $postfix::master_bounce_command
  $master_defer_command  = $postfix::master_defer_command
  $myorigin            = $postfix::myorigin
  $manage_mailname     = $postfix::manage_mailname
  $manage_aliases      = $postfix::manage_aliases
  $manage_root_alias   = $postfix::manage_root_alias
  $root_mail_recipient = $postfix::root_mail_recipient
@@ -41,12 +43,14 @@ class postfix::files {
    replace => $manage_conffiles,
  }

  if $manage_mailname {
    file { '/etc/mailname':
      ensure  => 'file',
      content => "${::fqdn}\n",
      mode    => '0644',
      seltype => $postfix::params::seltype,
    }
  }

  # Aliases
  if $manage_aliases {
@@ -73,10 +77,10 @@ class postfix::files {
    )
  }

  file { '/etc/postfix/master.cf':
  file { "${postfix::confdir}/master.cf":
    ensure  => 'file',
    content => $_mastercf_content,
    group   => 'root',
    group   => $postfix::root_group,
    mode    => '0644',
    owner   => 'root',
    seltype => $postfix::params::seltype,
@@ -84,9 +88,9 @@ class postfix::files {
  }

  # Config files
  file { '/etc/postfix/main.cf':
  file { "${postfix::confdir}/main.cf":
    ensure  => 'file',
    group   => 'root',
    group   => $postfix::root_group,
    mode    => '0644',
    owner   => 'root',
    replace => false,
Loading