Giter Club home page Giter Club logo

puppet-postfix's Introduction

postfix

Build Status Code Coverage Puppet Forge Puppet Forge - downloads Puppet Forge - endorsement Puppet Forge - scores

Table of Contents

  1. Overview
  2. Module Description - What the module does and why it is useful
  3. Setup - The basics of getting started with postfix
  4. Usage - Configuration options and additional functionality
  5. Reference - An under-the-hood peek at what the module is doing and how
  6. Limitations - OS compatibility, etc.
  7. Development - Guide for contributing to the module

Overview

This module installs, configures and manages the Postfix service.

Module Description

This module handles installing, configuring and running Postfix across a range of operating systems and distributions.

Setup

What postfix affects

  • postfix package.
  • postfix configuration file.
  • postfix service.

Setup Requirements

Beginning with postfix

Install postfix with the default parameters (No configuration files will be changed).

    class { 'postfix': }

Install postfix with the recommended parameters.

    class { 'postfix':
      config_file_template => "postfix/${::operatingsystem}/etc/postfix/main.cf.erb",
      config_file_hash     => {
        'mailname' => {
          config_file_path   => '/etc/mailname',
          config_file_string => "${::fqdn}\n",
        },
      },
    }

Usage

Update the postfix package.

    class { 'postfix':
      package_ensure => 'latest',
    }

Remove the postfix package.

    class { 'postfix':
      package_ensure => 'absent',
    }

Purge the postfix package (All configuration files will be removed).

    class { 'postfix':
      package_ensure => 'purged',
    }

Deploy the configuration files from source directory.

    class { 'postfix':
      config_dir_source => "puppet:///modules/postfix/${::operatingsystem}/etc/postfix",
    }

Deploy the configuration files from source directory (Unmanaged configuration files will be removed).

    class { 'postfix':
      config_dir_purge  => true,
      config_dir_source => "puppet:///modules/postfix/${::operatingsystem}/etc/postfix",
    }

Deploy the configuration file from source.

    class { 'postfix':
      config_file_source => "puppet:///modules/postfix/${::operatingsystem}/etc/postfix/main.cf",
    }

Deploy the configuration file from string.

    class { 'postfix':
      config_file_string => '# THIS FILE IS MANAGED BY PUPPET',
    }

Deploy the configuration file from template.

    class { 'postfix':
      config_file_template => "postfix/${::operatingsystem}/etc/postfix/main.cf.erb",
    }

Deploy the configuration file from custom template (Additional parameters can be defined).

    class { 'postfix':
      config_file_template     => "postfix/${::operatingsystem}/etc/postfix/main.cf.erb",
      config_file_options_hash => {
        'key' => 'value',
      },
    }

Deploy additional configuration files from source, string or template.

    class { 'postfix':
      config_file_hash => {
        'postfix.2nd.conf' => {
          config_file_path   => '/etc/postfix/postfix.2nd.conf',
          config_file_source => "puppet:///modules/postfix/${::operatingsystem}/etc/postfix/postfix.2nd.conf",
        },
        'postfix.3rd.conf' => {
          config_file_path   => '/etc/postfix/postfix.3rd.conf',
          config_file_string => '# THIS FILE IS MANAGED BY PUPPET',
        },
        'postfix.4th.conf' => {
          config_file_path     => '/etc/postfix/postfix.4th.conf',
          config_file_template => "postfix/${::operatingsystem}/etc/postfix/postfix.4th.conf.erb",
        },
      },
    }

Disable the postfix service.

    class { 'postfix':
      service_ensure => 'stopped',
    }

Reference

Classes

Public Classes

  • postfix: Main class, includes all other classes.

Private Classes

  • postfix::install: Handles the packages.
  • postfix::config: Handles the configuration file.
  • postfix::service: Handles the service.

Parameters

package_ensure

Determines if the package should be installed. Valid values are 'present', 'latest', 'absent' and 'purged'. Defaults to 'present'.

package_name

Determines the name of package to manage. Defaults to 'postfix'.

package_list

Determines if additional packages should be managed. Defaults to '['swaks']'.

config_dir_ensure

Determines if the configuration directory should be present. Valid values are 'absent' and 'directory'. Defaults to 'directory'.

config_dir_path

Determines if the configuration directory should be managed. Defaults to '/etc/postfix'

config_dir_purge

Determines if unmanaged configuration files should be removed. Valid values are 'true' and 'false'. Defaults to 'false'.

config_dir_recurse

Determines if the configuration directory should be recursively managed. Valid values are 'true' and 'false'. Defaults to 'true'.

config_dir_source

Determines the source of a configuration directory. Defaults to 'undef'.

config_file_ensure

Determines if the configuration file should be present. Valid values are 'absent' and 'present'. Defaults to 'present'.

config_file_path

Determines if the configuration file should be managed. Defaults to '/etc/postfix/main.cf'

config_file_owner

Determines which user should own the configuration file. Defaults to 'root'.

config_file_group

Determines which group should own the configuration file. Defaults to 'root'.

config_file_mode

Determines the desired permissions mode of the configuration file. Defaults to '0644'.

config_file_source

Determines the source of a configuration file. Defaults to 'undef'.

config_file_string

Determines the content of a configuration file. Defaults to 'undef'.

config_file_template

Determines the content of a configuration file. Defaults to 'undef'.

config_file_notify

Determines if the service should be restarted after configuration changes. Defaults to 'Service[postfix]'.

config_file_require

Determines which package a configuration file depends on. Defaults to 'Package[postfix]'.

config_file_hash

Determines which configuration files should be managed via postfix::define. Defaults to '{}'.

config_file_options_hash

Determines which parameters should be passed to an ERB template. Defaults to '{}'.

service_ensure

Determines if the service should be running or not. Valid values are 'running' and 'stopped'. Defaults to 'running'.

service_name

Determines the name of service to manage. Defaults to 'postfix'.

service_enable

Determines if the service should be enabled at boot. Valid values are 'true' and 'false'. Defaults to 'true'.

myhostname

Determines the internet domain name of this mail system. Defaults to "$::fqdn".

mydestination

Determines the list of domains that are delivered via the $local_transport mail delivery transport. Defaults to "${::fqdn}, localhost.${::domain}, localhost".

recipient

Determines which email address should be used for the redirecting. Defaults to "admin@${::domain}".

relayhost

Determines which host should be used as relayhost for outgoing emails. Defaults to "smtp.${::domain}".

relayport

Determines which port should be used as relayhost for outgoing emails. Defaults to '25'.

sasl_user

Determines which user should be used for authentication with the relayhost. Defaults to 'undef'.

sasl_pass

Determines which password should be used for authentication with the relayhost. Defaults to 'undef'.

Limitations

This module has been tested on:

  • Debian 6/7/8
  • Ubuntu 12.04/14.04/16.04
  • Gentoo Base System release 2.2

Development

Bug Report

If you find a bug, have trouble following the documentation or have a question about this module - please create an issue.

Pull Request

If you are able to patch the bug or add the feature yourself - please make a pull request.

Contributors

The list of contributors can be found at: https://github.com/dhoppe/puppet-postfix/graphs/contributors

puppet-postfix's People

Contributors

dhoppe avatar rocco83 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

puppet-postfix's Issues

additional mailalias support

Hi,

It would be good to support additional mailalias.
The problem is the refresh of newaliases, that is missing for external definition.
Currently only the included mailalias is subscribed
https://github.com/dhoppe/puppet-postfix/blob/master/manifests/config.pp#L55

The best would be to have a wrapper to define it, as we can define some template.
And/Or, the following may be added
Mailalias <| |> ~> Exec['postfix.newaliases']

I think the first is the best one, but comments are welcome.

Documentation Help -> SMTP relay (using sasl?)

I'm new to puppet and attempting to setup a VPS using postfix as a relay to sparkpost as per that link, the config should be

smtp_sasl_auth_enable = yes 
smtp_sasl_password_maps = static:SMTP_Injection:<your API key>
relayhost = [smtp.sparkpostmail.com]:587
smtp_sasl_security_options = noanonymous 
smtp_tls_security_level = encrypt
header_size_limit = 4096000

But I'm having trouble trying to work out how to set this up with your plugin. I searched through the source and I found where you have the template and I can see there's a section there about scope['::postfix::sasl_user'] but I don't understand how to override the bits I need to override.

I'm sure you're a very busy person so please just close this and I'll try and work it out, but any help would be really appreciated, and the README did say to open an issue about documentation! (I'd be happy to make a PR with a section on configuring the relay if you'd want it)

Thanks!
Patrick

Calling postmap

Hi,

Might have missed something, but is there a way to call postmap on a file with this module ?
Seems to fit our needs except for managing the transport file which need to be postmap'ed.

I defined, in hiera, the config like this :

postfix::config_file_hash:
  master.cf:
    config_file_path: '/etc/postfix/master.cf'
    config_file_source: 'puppet:///modules/postfix/master.cf'
  transport:
    config_file_path: '/etc/postfix/transport'
    config_file_source: 'puppet:///modules/postfix/transport'

Is there a way to define that transport should be postmap'ed ?
thanks !

PS : Sorry for the lot of edits but I really can't get used to github markdown.

masquerade_domains and canonical maps are not supported !

Hi,
only wanted to mention, that these often used features are not supported.

My fix:

diff -upr puppet-postfix/manifests/config.pp puppet-postfix-new/manifests/config.pp
--- puppet-postfix/manifests/config.pp    2016-06-13 10:53:41.343218152 +0200
+++ puppet-postfix-new/manifests/config.pp    2016-06-13 09:08:46.344678602 +0200
@@ -62,4 +62,25 @@ class postfix::config {
       recipient => $::postfix::recipient,
     }
   }
+
+  if $::postfix::sender_canonical_maps {
+    exec { 'postfix.canonical.postmap':
+      command     => "/usr/sbin/postmap ${::postfix::config_dir_path}/sender_canonical",
+      refreshonly => true,
+      subscribe   => File['postfix.sender_canonical'],
+      require     => $::postfix::config_file_require,
+    }
+
+    file { 'postfix.sender_canonical':
+      ensure  => $::postfix::config_file_ensure,
+      path    => "${::postfix::config_dir_path}/sender_canonical",
+      owner   => $::postfix::config_file_owner,
+      group   => $::postfix::config_file_group,
+      mode    => '0600',
+      content => template('postfix/common/etc/postfix/sender_canonical.erb'),
+      notify  => $::postfix::config_file_notify,
+      require => $::postfix::config_file_require,
+    }
+  }
+
 }
diff -upr puppet-postfix/manifests/init.pp puppet-postfix-new/manifests/init.pp
--- puppet-postfix/manifests/init.pp    2016-06-13 10:53:41.343218152 +0200
+++ puppet-postfix-new/manifests/init.pp    2016-06-13 09:14:10.431548196 +0200
@@ -29,12 +29,14 @@ class postfix (
   $service_enable           = true,

   $myhostname               = $::fqdn,
+  $masquerade_domains       = undef,
   $mydestination            = "${::fqdn}, localhost.${::domain}, localhost",
   $recipient                = "admin@${::domain}",
   $relayhost                = "smtp.${::domain}",
   $relayport                = 25,
   $sasl_user                = undef,
   $sasl_pass                = undef,
+  $sender_canonical_maps    = undef,
 ) inherits ::postfix::params {
   validate_re($package_ensure, '^(absent|latest|present|purged)$')
   validate_string($package_name)
@@ -59,6 +61,8 @@ class postfix (
   validate_hash($config_file_hash)
   validate_hash($config_file_options_hash)

+  if $sender_canonical_maps { validate_hash($sender_canonical_maps) }
+
   validate_re($service_ensure, '^(running|stopped)$')
   validate_string($service_name)
   validate_bool($service_enable)
diff -upr puppet-postfix/metadata.json puppet-postfix-new/metadata.json
--- puppet-postfix/metadata.json    2016-06-13 10:53:41.343218152 +0200
+++ puppet-postfix-new/metadata.json    2016-02-16 22:20:20.000000000 +0100
@@ -8,11 +8,9 @@
   "project_page": "https://github.com/dhoppe/puppet-postfix",
   "issues_url": "https://github.com/dhoppe/puppet-postfix/issues",
   "dependencies": [
-    {
-      "name": "puppetlabs/stdlib",
-      "version_requirement": ">= 4.5.0 < 5.0.0"
-    }
+    {"name":"puppetlabs/stdlib","version_requirement":">= 4.5.0 < 5.0.0"}
   ],
+  "data_provider": null,
   "operatingsystem_support": [
     {
       "operatingsystem": "Debian",
Only in puppet-postfix: .rspec
Only in puppet-postfix: .rubocop.yml
Only in puppet-postfix-new/templates/common/etc/postfix: sender_canonical.erb
diff -upr puppet-postfix/templates/Debian/etc/postfix/main.cf.erb puppet-postfix-new/templates/Debian/etc/postfix/main.cf.erb
--- puppet-postfix/templates/Debian/etc/postfix/main.cf.erb    2016-06-13 10:53:41.343218152 +0200
+++ puppet-postfix-new/templates/Debian/etc/postfix/main.cf.erb    2016-06-13 09:50:05.405681722 +0200
@@ -33,6 +33,12 @@ smtp_tls_note_starttls_offer = yes
 smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

 <% end -%>
+
+<% if scope['::postfix::sender_canonical_maps'] -%>
+sender_canonical_maps = hash:/etc/postfix/sender_canonical
+
+<% end -%>
+
 # TLS parameters
 smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
 smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
@@ -44,6 +50,7 @@ smtp_tls_session_cache_database = btree:
 # information on enabling SSL in the smtp client.

 myhostname = <%= scope['::postfix::myhostname'] %>
+masquerade_domains = <%= scope['::postfix::masquerade_domains'] %>
 alias_maps = hash:/etc/aliases
 alias_database = hash:/etc/aliases
 myorigin = /etc/mailname
diff -upr puppet-postfix/templates/Ubuntu/etc/postfix/main.cf.erb puppet-postfix-new/templates/Ubuntu/etc/postfix/main.cf.erb
--- puppet-postfix/templates/Ubuntu/etc/postfix/main.cf.erb    2016-06-13 10:53:41.343218152 +0200
+++ puppet-postfix-new/templates/Ubuntu/etc/postfix/main.cf.erb    2016-06-13 09:48:10.340096281 +0200
@@ -33,6 +33,12 @@ smtp_tls_note_starttls_offer = yes
 smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

 <% end -%>
+
+<% if scope['::postfix::sender_canonical_maps'] -%>
+sender_canonical_maps = hash:/etc/postfix/sender_canonical
+
+<% end -%>
+
 # TLS parameters
 smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
 smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

The erb template: (templates/common/etc/postfix/sender_canonical.erb)

#
# THIS FILE IS MANAGED BY PUPPET
# <%= file %>
#


<% if scope['::postfix::sender_canonical_maps'] -%>
<% scope['::postfix::sender_canonical_maps'].each do |key,value| -%>
<%= value['username'] %> <%= value['email'] %>
<% end -%>
<% end -%>

Example class snippet:

$users = {
  "root" => {
            "username" => "root",
            "email" => "root-${::hostname}@domain.com"
  },
  "postmaster" => {
            "username" => "postmaster",
            "email" => "postmaster-${::hostname}@domain.com"
  }
}

class { 'postfix':
    recipient => "postmaster",
    relayhost => "relay.domain.com",
    relayport => "25",
    sasl_user => "relay",
    sasl_pass => "xxxxxxxxxxxxxx",
    masquerade_domains => "${::domain}",
    sender_canonical_maps => $users,
    config_file_template => "postfix/${::operatingsystem}/etc/postfix/main.cf.erb"
  }

Rgds.

Franz

Set empty relayhost?

Wondering how to set an empty relayhost (" relayhost = " in main.cf).
Hiera complains with:
Could not find data item host in any Hiera data file and no default supplied at /.../puppet/modules/postfix/manifests/init.pp:56 on node xxx

I've tried using "", undef, etc.

Thanks!

hard-coded hiera settings?

Hi, if I read your code correctly, there are hardcoded values from hiera in templates... omg this is so wrong.... what if I need to define for example hostrelay in puppet class?

for example having customized hiera config:

custom::postfix::package_ensure: 'latest'
custom::postfix::relayhost: 'smtp1.prod.cnc'

and defined class for it:

class custom::postfix ($package_ensure, $relayhost) {
 
    class { 'postfix':
            package_ensure => $package_ensure,
            relayhost      => 'smtp1.prod.cnc',
    }
}

but this doesn't work because your module expects only one exact hiera structure and even it uses class parameters with it's default values it never uses them in erb templates! this could be quite nice, almost dependency free module, but this really sucks :-(
Please, make it more flexible by using internal variables which you already have defined.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.