Skip to content
Snippets Groups Projects
Commit 6232194a authored by Raphaël Pinson's avatar Raphaël Pinson
Browse files

Merge pull request #33 from raphink/dev/refactor

Refactor postfix module
parents 364c2bff 6f078e57
No related branches found
No related tags found
No related merge requests found
Showing
with 552 additions and 374 deletions
fixtures:
repositories:
"augeas": "git://github.com/camptocamp/puppet-augeas.git"
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
symlinks:
"postfix": "#{source_dir}"
......@@ -32,7 +32,7 @@ let space_or_eol (sep:regexp) (default:string) =
del (space_or_eol_re? . sep . space_or_eol_re?) default
(* View: word *)
let word = store /[A-Za-z0-9@\*.-]+/
let word = store /[A-Za-z0-9@\*.+-]+/
(* View: comma *)
let comma = space_or_eol "," ", "
......
#class postfix::augeas
# This class provides the augeas lenses used by the postfix class
#
class postfix::augeas {
augeas::lens {'postfix_transport':
ensure => present,
lens_source => 'puppet:///modules/postfix/lenses/postfix_transport.aug',
test_source => 'puppet:///modules/postfix/lenses/test_postfix_transport.aug',
stock_since => '1.0.0',
}
augeas::lens {'postfix_virtual':
ensure => present,
lens_source => 'puppet:///modules/postfix/lenses/postfix_virtual.aug',
test_source => 'puppet:///modules/postfix/lenses/test_postfix_virtual.aug',
stock_since => '1.0.0',
}
}
......@@ -4,31 +4,30 @@
# Uses the "postconf" command to add/alter/remove options in postfix main
# configuation file (/etc/postfix/main.cf).
#
#Parameters:
#- *name*: name of the parameter.
#- *ensure*: present/absent. defaults to present.
#- *value*: value of the parameter.
# === Parameters
#
#Requires:
#- Class["postfix"]
# [*name*] - name of the parameter.
# [*ensure*] - present/absent. defaults to present.
# [*value*] - value of the parameter.
#
#Example usage:
# === Requires
#
# node "toto.example.com" {
# - Class["postfix"]
#
# include postfix
# === Examples
#
# postfix::config {
# "smtp_use_tls" => "yes";
# "smtp_sasl_auth_enable" => "yes";
# "smtp_sasl_password_maps" => "hash:/etc/postfix/my_sasl_passwords";
# "relayhost" => "[mail.example.com]:587";
# }
# postfix::config { 'smtp_use_tls':
# ensure => 'present',
# value => 'yes',
# }
#
#
define postfix::config ($value, $ensure = present) {
validate_string($value)
validate_string($ensure)
validate_re($ensure, ['present', 'absent'],
"\$ensure must be either 'present' or 'absent', got '${ensure}'")
Augeas {
incl => '/etc/postfix/main.cf',
lens => 'Postfix_Main.lns',
......@@ -39,12 +38,12 @@ define postfix::config ($value, $ensure = present) {
case $ensure {
present: {
augeas { "set postfix '${name}' to '${value}'":
changes => "set $name '$value'",
changes => "set ${name} '${value}'",
}
}
absent: {
augeas { "rm postfix '${name}'":
changes => "rm $name",
changes => "rm ${name}",
}
}
default: {}
......
class postfix::files {
include postfix::params
$alias_maps = $postfix::all_alias_maps
$inet_interfaces = $postfix::inet_interfaces
$mail_user = $postfix::mail_user
$master_smtp = $postfix::master_smtp
$master_smtps = $postfix::master_smtps
$master_submission = $postfix::master_submission
$myorigin = $postfix::myorigin
$root_mail_recipient = $postfix::root_mail_recipient
$smtp_listen = $postfix::_smtp_listen
$use_amavisd = $postfix::use_amavisd
$use_dovecot_lda = $postfix::use_dovecot_lda
$use_schleuder = $postfix::use_schleuder
$use_sympa = $postfix::use_sympa
file { '/etc/mailname':
ensure => 'file',
content => "${::fqdn}\n",
seltype => $postfix::params::seltype,
}
# Aliases
file { '/etc/aliases':
ensure => 'file',
content => "# file managed by puppet\n",
notify => Exec['newaliases'],
replace => false,
seltype => $postfix::params::seltype,
}
# Aliases
exec { 'newaliases':
command => '/usr/bin/newaliases',
refreshonly => true,
subscribe => File['/etc/aliases'],
}
# Config files
if $postfix::mastercf_source {
$mastercf_content = undef
} else {
$mastercf_content = template(
$postfix::params::master_os_template,
'postfix/master.cf.common.erb'
)
}
file { '/etc/postfix/master.cf':
ensure => 'file',
content => $mastercf_content,
group => 'root',
mode => '0644',
owner => 'root',
seltype => $postfix::params::seltype,
source => $postfix::mastercf_source,
}
# Config files
file { '/etc/postfix/main.cf':
ensure => 'file',
group => 'root',
mode => '0644',
owner => 'root',
replace => false,
seltype => $postfix::params::seltype,
source => $postfix::maincf_source,
}
::postfix::config {
'alias_maps': value => $alias_maps;
'inet_interfaces': value => $inet_interfaces;
'myorigin': value => $myorigin;
}
case $::osfamily {
'RedHat': {
::postfix::config {
'mailq_path': value => '/usr/bin/mailq.postfix';
'newaliases_path': value => '/usr/bin/newaliases.postfix';
'sendmail_path': value => '/usr/sbin/sendmail.postfix';
}
}
default: {}
}
mailalias {'root':
recipient => $root_mail_recipient,
notify => Exec['newaliases'],
}
}
......@@ -4,73 +4,56 @@
# "${name}.db" using the "postmap" command. The map file can then be referred to
# using postfix::config.
#
#Parameters:
#- *name*: the name of the map file.
#- *ensure*: present/absent, defaults to present.
#- *source*: file source.
# === Parameters
#
#Requires:
#- Class["postfix"]
# [*name*] - the name of the map file.
# [*ensure*] - present/absent, defaults to present.
# [*source*] - file source.
#
#Example usage:
# === Requires
#
# node "toto.example.com" {
# - Class["postfix"]
#
# include postfix
# === Examples
#
# postfix::hash { "/etc/postfix/virtual":
# postfix::hash { '/etc/postfix/virtual':
# ensure => present,
# }
# postfix::config { "virtual_alias_maps":
# value => "hash:/etc/postfix/virtual"
# }
# postfix::config { 'virtual_alias_maps':
# value => 'hash:/etc/postfix/virtual',
# }
#
define postfix::hash ($ensure='present', $source=false, $content=false) {
define postfix::hash (
$ensure='present',
$source=undef,
$content=undef,
) {
include ::postfix::params
# selinux labels differ from one distribution to another
case $::operatingsystem {
validate_absolute_path($name)
validate_string($source)
validate_string($content)
validate_string($ensure)
validate_re($ensure, ['present', 'absent'],
"\$ensure must be either 'present' or 'absent', got '${ensure}'")
RedHat, CentOS: {
case $::lsbmajdistrelease {
'4': { $postfix_seltype = 'etc_t' }
'5','6': { $postfix_seltype = 'postfix_etc_t' }
default: { $postfix_seltype = undef }
}
}
default: {
$postfix_seltype = undef
}
if $source and $content {
fail 'You must provide either \'source\' or \'content\', not both'
}
File {
mode => '0600',
owner => root,
group => root,
seltype => $postfix_seltype,
seltype => $postfix::params::seltype,
}
if $source != false {
file { $name:
ensure => $ensure,
source => $source,
require => Package['postfix'],
}
} else {
if $content != false {
file {$name:
ensure => $ensure,
content => $content,
require => Package['postfix'],
}
} else {
file {$name:
ensure => $ensure,
require => Package['postfix'],
}
}
}
file {"${name}.db":
ensure => $ensure,
......
......@@ -4,174 +4,156 @@
# This class provides a basic setup of postfix with local and remote
# delivery and an SMTP server listening on the loopback interface.
#
# Parameters:
# - *$postfix_smtp_listen*: address on which the smtp service will listen to.
# defaults to 127.0.0.1
# - *$root_mail_recipient*: who will recieve root's emails. defaults to 'nobody'
# === Parameters
#
# Example usage:
# [*alias_maps*] - (string)
#
# node 'toto.example.com' {
# $postfix_smtp_listen = '192.168.1.10'
# include postfix
# [*inet_interfaces*] - (string)
#
# [*ldap*] - (boolean) Whether to use LDAP
#
# [*ldap_base*] - (string)
#
# [*ldap_host*] - (string)
#
# [*ldap_options*] - (string)
#
# [*mail_user*] - (string) The mail user
#
# [*mailman*] - (boolean)
#
# [*maincf_source*] - (string)
#
# [*mastercf_source*] - (string)
#
# [*master_smtp*] - (string)
#
# [*master_smtps*] - (string)
#
# [*master_submission*] - (string)
#
# [*mta*] - (boolean) Configure postfix minimally, as a simple MTA
#
# [*mydestination*] - (string)
#
# [*mynetworks*] - (string)
#
# [*myorigin*] - (string)
#
# [*relayhost*] - (string)
#
# [*root_mail_recipient*] - (string)
#
# [*satellite*] - (boolean) Whether to use as a satellite
# (implies MTA)
#
# [*smtp_listen*] - (string) The SMTP listen interface
#
# [*use_amavisd*] - (boolean) Whether to setup for Amavis
#
# [*use_dovecot_lda*] - (boolean) Whether to setup for Dovecot LDA
#
# [*use_schleuder*] - (boolean) Whether to setup for Schleuder
#
# [*use_sympa*] - (boolean) Whether to setup for Sympa
#
# === Examples
#
# class { 'postfix':
# smtp_listen => '192.168.1.10',
# }
#
class postfix {
# selinux labels differ from one distribution to another
case $::operatingsystem {
RedHat, CentOS: {
case $::lsbmajdistrelease {
'4': { $postfix_seltype = 'etc_t' }
'5','6': { $postfix_seltype = 'postfix_etc_t' }
default: { $postfix_seltype = undef }
}
}
default: {
$postfix_seltype = undef
}
}
# Default value for various options
if $postfix_smtp_listen == '' {
$postfix_smtp_listen = '127.0.0.1'
}
if $root_mail_recipient == '' {
$root_mail_recipient = 'nobody'
}
if $postfix_use_amavisd == '' {
$postfix_use_amavisd = 'no'
}
if $postfix_use_dovecot_lda == '' {
$postfix_use_dovecot_lda = 'no'
}
if $postfix_use_schleuder == '' {
$postfix_use_schleuder = 'no'
}
if $postfix_use_sympa == '' {
$postfix_use_sympa = 'no'
}
if $postfix_mail_user == '' {
$postfix_mail_user = 'vmail'
}
case $::operatingsystem {
/RedHat|CentOS|Fedora/: {
$mailx_package = 'mailx'
}
/Debian|kFreeBSD/: {
$mailx_package = $::lsbdistcodename ? {
/lenny|etch|sarge/ => 'mailx',
default => 'bsd-mailx',
}
}
'Ubuntu': {
if (versioncmp('10', $::lsbmajdistrelease) > 0) {
$mailx_package = 'mailx'
} else {
$mailx_package = 'bsd-mailx'
}
}
}
$master_os_template = $::operatingsystem ? {
/RedHat|CentOS/ => template('postfix/master.cf.redhat.erb', 'postfix/master.cf.common.erb'),
/Debian|Ubuntu|kFreeBSD/ => template('postfix/master.cf.debian.erb', 'postfix/master.cf.common.erb'),
}
package { 'postfix':
ensure => installed,
}
package { 'mailx':
ensure => installed,
name => $mailx_package,
}
service { 'postfix':
ensure => running,
enable => true,
hasstatus => true,
restart => '/etc/init.d/postfix reload',
require => Package['postfix'],
}
file { '/etc/mailname':
ensure => present,
content => "$::fqdn\n",
seltype => $postfix_seltype,
}
# Aliases
file { '/etc/aliases':
ensure => present,
content => '# file managed by puppet\n',
replace => false,
seltype => $postfix_seltype,
notify => Exec['newaliases'],
}
# Aliases
exec { 'newaliases':
command => '/usr/bin/newaliases',
refreshonly => true,
require => Package['postfix'],
subscribe => File['/etc/aliases'],
}
# Config files
file { '/etc/postfix/master.cf':
ensure => present,
owner => 'root',
group => 'root',
mode => '0644',
content => $master_os_template,
seltype => $postfix_seltype,
notify => Service['postfix'],
require => Package['postfix'],
}
# Config files
file { '/etc/postfix/main.cf':
ensure => present,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/postfix/main.cf',
replace => false,
seltype => $postfix_seltype,
notify => Service['postfix'],
require => Package['postfix'],
}
# Default configuration parameters
$myorigin = $valid_fqdn ? {
'' => $::fqdn,
default => $valid_fqdn,
}
postfix::config {
'myorigin': value => $myorigin;
'alias_maps': value => 'hash:/etc/aliases';
'inet_interfaces': value => 'all';
}
case $::operatingsystem {
RedHat, CentOS: {
postfix::config {
'sendmail_path': value => '/usr/sbin/sendmail.postfix';
'newaliases_path': value => '/usr/bin/newaliases.postfix';
'mailq_path': value => '/usr/bin/mailq.postfix';
}
}
default: {}
}
mailalias {'root':
recipient => $root_mail_recipient,
notify => Exec['newaliases'],
class postfix (
$alias_maps = 'hash:/etc/aliases',
$inet_interfaces = 'all',
$ldap = false,
$ldap_base = undef,
$ldap_host = undef,
$ldap_options = undef,
$mail_user = 'vmail', # postfix_mail_user
$mailman = false,
$maincf_source = "puppet:///modules/${module_name}/main.cf",
$mastercf_source = undef,
$master_smtp = undef, # postfix_master_smtp
$master_smtps = undef, # postfix_master_smtps
$master_submission = undef, # postfix_master_submission
$mta = false,
$mydestination = '$myorigin', # postfix_mydestination
$mynetworks = '127.0.0.0/8', # postfix_mynetworks
$myorigin = $::fqdn,
$relayhost = undef, # postfix_relayhost
$root_mail_recipient = 'nobody', # root_mail_recipient
$satellite = false,
$smtp_listen = '127.0.0.1', # postfix_smtp_listen
$use_amavisd = false, # postfix_use_amavisd
$use_dovecot_lda = false, # postfix_use_dovecot_lda
$use_schleuder = false, # postfix_use_schleuder
$use_sympa = false, # postfix_use_sympa
) inherits postfix::params {
validate_bool($ldap)
validate_bool($mailman)
validate_bool($mta)
validate_bool($satellite)
validate_bool($use_amavisd)
validate_bool($use_dovecot_lda)
validate_bool($use_schleuder)
validate_bool($use_sympa)
validate_string($alias_maps)
validate_string($inet_interfaces)
validate_string($ldap_base)
validate_string($ldap_host)
validate_string($ldap_options)
validate_string($mail_user)
validate_string($maincf_source)
validate_string($mastercf_source)
validate_string($master_smtp)
validate_string($master_smtps)
validate_string($mydestination)
validate_string($mynetworks)
validate_string($myorigin)
validate_string($relayhost)
validate_string($root_mail_recipient)
validate_string($smtp_listen)
$_smtp_listen = $mailman ? {
true => '0.0.0.0',
default => $smtp_listen,
}
$all_alias_maps = $ldap ? {
false => $alias_maps,
true => "\"${alias_maps}, ldap:/etc/postfix/ldap-aliases.cf\"",
}
class { 'postfix::packages': } ->
class { 'postfix::files': } ~>
class { 'postfix::service': } ->
Class['postfix']
if $ldap {
include ::postfix::ldap
}
if $mta {
if $satellite {
fail('enabling both the $mta and $satellite parameters is not supported. Please disable one.')
}
include ::postfix::mta
}
if $satellite {
if $mta {
fail('enabling both the $mta and $satellite parameters is not supported. Please disable one.')
}
include ::postfix::satellite
}
if $mailman {
include ::postfix::mailman
}
}
class postfix::ldap inherits postfix {
Postfix::Config['alias_maps'] {
value => '"hash:/etc/aliases, ldap:/etc/postfix/ldap-aliases.cf"',
}
# == Class: postfix::ldap
#
# Configures postfix for use with LDAP.
#
# === Parameters
#
# === Requires
#
# - Class["postfix"]
#
# === Examples
#
# include postfix
# include postfix::ldap
#
class postfix::ldap {
package {'postfix-ldap': }
if ! $::postfix_ldap_base {
fail 'Missing $postfix_ldap_base !'
if ! $postfix::ldap_base {
fail 'Missing $postfix::ldap_base !'
}
$ldap_host = $postfix::ldap_host ? {
undef => 'localhost',
default => $postfix::ldap_host,
}
$ldap_base = $postfix::ldap_base
$ldap_options = $postfix::ldap_options ? {
undef => '',
default => $postfix::ldap_options,
}
file {'/etc/postfix/ldap-aliases.cf':
ensure => present,
owner => root,
group => postfix,
ensure => 'file',
owner => 'root',
group => 'postfix',
content => template('postfix/postfix-ldap-aliases.cf.erb'),
require => Package['postfix-ldap'],
}
......
#
# == Class: postfix::mailman
#
# Configures a basic smtp server, able to work for the mailman mailing-list
# manager.
#
# Parameters:
# - every global variable which works for class 'postfix' will work here.
# === Examples
#
# Example usage:
# /!\ Do not include this class directly,
# use mailman => true in the postfix top class!
#
# node 'toto.example.com' {
# include mailman
# include postfix::mailman
# class { 'postfix':
# mailman => true,
# }
#
class postfix::mailman {
$postfix_smtp_listen = '0.0.0.0'
include postfix
postfix::config {
'virtual_alias_maps':
......@@ -28,11 +23,11 @@ class postfix::mailman {
}
postfix::hash { '/etc/postfix/virtual':
ensure => present,
ensure => 'present',
}
postfix::hash { '/etc/postfix/transport':
ensure => present,
ensure => 'present',
}
}
#
# == Class: postfix::mta
#
# This class configures a minimal MTA, listening on
# $postfix_smtp_listen (default to localhost) and delivering mail to
# $postfix_mydestination (default to $fqdn).
# This class configures a minimal MTA, delivering mail to
# $mydestination.
#
# A valid relay host is required ($postfix_relayhost) for outbound email.
# A valid relay host is required ($relayhost) for outbound email.
#
# transport & virtual maps get configured and can be populated with
# postfix::transport and postfix::virtual
#
# Parameters:
# - *$postfix_relayhost*
# - *$postfix_mydestination*
# - every global variable which works for class 'postfix' will work here.
#
# Example usage:
# === Parameters
#
# node 'toto.example.com' {
# $postfix_relayhost = 'mail.example.com'
# $postfix_smtp_listen = '0.0.0.0'
# $postfix_mydestination = '$myorigin, myapp.example.com'
# [*relayhost*] - (string) the relayhost to use
# [*mydestination*] - (string)
# [*mynetworks*] - (string)
#
# include postfix::mta
# === Examples
#
# postfix::transport { 'myapp.example.com':
# ensure => present,
# destination => 'local:',
# }
# class { 'postfix':
# relayhost => 'mail.example.com',
# smtp_listen => '0.0.0.0',
# mydestination => '$myorigin, myapp.example.com',
# mta => true,
# }
#
class postfix::mta {
case $postfix_relayhost {
'': { fail('Required $postfix_relayhost variable is not defined.') }
default: {}
}
case $postfix_mydestination {
'': { $postfix_mydestination = '$myorigin' }
default: {}
}
case $postfix_mynetworks {
"": { $postfix_mynetworks = "127.0.0.0/8" }
default: {}
}
class postfix::mta (
$mydestination = $postfix::mydestination,
$mynetworks = $postfix::mynetworks,
$relayhost = $postfix::relayhost,
) {
include postfix
validate_re($relayhost, '^\S+$',
'Wrong value for $relayhost')
validate_re($mydestination, '^\S+$',
'Wrong value for $mydestination')
validate_re($mynetworks, '^\S+$',
'Wrong value for $mynetworks')
postfix::config {
'mydestination': value => $postfix_mydestination;
'mynetworks': value => $postfix_mynetworks;
'relayhost': value => $postfix_relayhost;
'mydestination': value => $mydestination;
'mynetworks': value => $mynetworks;
'relayhost': value => $relayhost;
'virtual_alias_maps': value => 'hash:/etc/postfix/virtual';
'transport_maps': value => 'hash:/etc/postfix/transport';
}
postfix::hash { '/etc/postfix/virtual':
ensure => present,
ensure => 'present',
}
postfix::hash { '/etc/postfix/transport':
ensure => present,
ensure => 'present',
}
}
class postfix::packages {
include postfix::params
package { 'postfix':
ensure => installed,
}
package { 'mailx':
ensure => installed,
name => $postfix::params::mailx_package,
}
}
class postfix::params {
case $::osfamily {
'RedHat': {
$seltype = $::lsbmajdistrelease ? {
'4' => 'etc_t',
/5|6/ => 'postfix_etc_t',
default => undef,
}
$mailx_package = 'mailx'
$master_os_template = "${module_name}/master.cf.redhat.erb"
}
'Debian': {
$seltype = undef
$mailx_package = $::lsbdistcodename ? {
/sarge|etch|lenny|lucid/ => 'mailx',
default => 'bsd-mailx',
}
$master_os_template = "${module_name}/master.cf.debian.erb"
}
default: {
fail "Unsupported OS family '${::osfamily}'"
}
}
}
......@@ -2,37 +2,42 @@
# == Class: postfix::satellite
#
# This class configures all local email (cron, mdadm, etc) to be forwarded
# to $root_mail_recipient, using $postfix_relayhost as a relay.
# to $root_mail_recipient, using $relayhost as a relay.
#
# $valid_fqdn can be set to override $fqdn in the case where the FQDN is
# not recognized as valid by the destination server.
# This class will call postfix::mta and override its parameters.
# You shouldn't call postfix::mta yourself or use mta=true in the postfix class.
#
# Parameters:
# - *valid_fqdn*
# - every global variable which works for class 'postfix' will work here.
# === Parameters
#
# Example usage:
# [*mydestination*] - (string)
# [*mynetworks*] - (string)
# [*relayhost*] - (string)
#
# node 'toto.local.lan' {
# $postfix_relayhost = 'mail.example.com'
# $valid_fqdn = 'toto.example.com'
# $root_mail_recipient = 'the.sysadmin@example.com'
# === Examples
#
# include postfix::satellite
# class { 'postfix':
# relayhost => 'mail.example.com',
# myorigin => 'toto.example.com',
# root_mail_recipient => 'the.sysadmin@example.com',
# satellite => true,
# }
#
class postfix::satellite {
class postfix::satellite (
$mydestination = $postfix::mydestination,
$mynetworks = $postfix::mynetworks,
$relayhost = $postfix::relayhost,
) {
# If $valid_fqdn exists, use it to override $fqdn
case $valid_fqdn {
'': { $valid_fqdn = $::fqdn }
default: { $fqdn = $valid_fqdn }
}
validate_re($postfix::myorigin, '^\S+$')
include postfix::mta
class { '::postfix::mta':
mydestination => $mydestination,
mynetworks => $mynetworks,
relayhost => $relayhost,
}
postfix::virtual { "@${valid_fqdn}":
ensure => present,
postfix::virtual { "@${postfix::myorigin}":
ensure => 'present',
destination => 'root',
}
}
class postfix::service {
service { 'postfix':
ensure => running,
enable => true,
hasstatus => true,
restart => '/etc/init.d/postfix reload',
}
}
......@@ -2,18 +2,20 @@
#
# Manages content of the /etc/postfix/transport map.
#
#Parameters:
#- *name*: name of address postfix will lookup. See transport(5).
#- *destination*: where the emails will be delivered to. See transport(5).
#- *ensure*: present/absent, defaults to present.
# === Parameters
#
# [*name*] - name of address postfix will lookup. See transport(5).
# [*destination*] - where the emails will be delivered to. See transport(5).
# [*ensure*] - present/absent, defaults to present.
#
# === Requires
#
#Requires:
# - Class["postfix"]
# - Postfix::Hash["/etc/postfix/transport"]
# - Postfix::Config["transport_maps"]
# - augeas
#
#Example usage:
# === Examples
#
# node "toto.example.com" {
#
......@@ -39,6 +41,12 @@ define postfix::transport (
) {
include postfix::augeas
validate_string($destination)
validate_string($nexthop)
validate_string($file)
validate_absolute_path($file)
validate_string($ensure)
case $ensure {
'present': {
if ($destination) {
......@@ -65,7 +73,7 @@ define postfix::transport (
}
default: {
fail("Wrong ensure value: ${ensure}")
fail "\$ensure must be either 'present' or 'absent', got '${ensure}'"
}
}
......
......@@ -2,18 +2,20 @@
#
# Manages content of the /etc/postfix/virtual map.
#
#Parameters:
#- *name*: name of address postfix will lookup. See virtual(8).
#- *destination*: where the emails will be delivered to. See virtual(8).
#- *ensure*: present/absent, defaults to present.
# === Parameters
#
# [*name*] - name of address postfix will lookup. See virtual(8).
# [*destination*] - where the emails will be delivered to. See virtual(8).
# [*ensure*] - present/absent, defaults to present.
#
# === Requires
#
#Requires:
# - Class["postfix"]
# - Postfix::Hash["/etc/postfix/virtual"]
# - Postfix::Config["virtual_alias_maps"]
# - augeas
#
#Example usage:
# === Examples
#
# node "toto.example.com" {
#
......@@ -33,12 +35,16 @@
#
define postfix::virtual (
$destination,
$nexthop='',
$file='/etc/postfix/virtual',
$ensure='present'
) {
include postfix::augeas
validate_string($destination)
validate_string($file)
validate_absolute_path($file)
validate_string($ensure)
case $ensure {
'present': {
$changes = [
......@@ -53,7 +59,7 @@ define postfix::virtual (
}
default: {
fail("Wrong ensure value: ${ensure}")
fail "\$ensure must be either 'present' or 'absent', got '${ensure}'"
}
}
......@@ -61,7 +67,7 @@ define postfix::virtual (
incl => $file,
lens => 'Postfix_Virtual.lns',
changes => $changes,
require => [Package['postfix'], Augeas::Lens['postfix_transport']],
require => [Package['postfix'], Augeas::Lens['postfix_virtual']],
notify => Exec['generate /etc/postfix/virtual.db'],
}
}
--format
s
--colour
--loadby
mtime
--backtrace
require 'spec_helper'
describe 'postfix::augeas' do
let (:facts) { {
:operatingsystem => 'Debian',
:osfamily => 'Debian',
} }
it { should contain_augeas__lens('postfix_transport').with(
:ensure => 'present',
:lens_source => 'puppet:///modules/postfix/lenses/postfix_transport.aug',
:test_source => 'puppet:///modules/postfix/lenses/test_postfix_transport.aug',
:stock_since => '1.0.0'
) }
it { should contain_augeas__lens('postfix_virtual').with(
:ensure => 'present',
:lens_source => 'puppet:///modules/postfix/lenses/postfix_virtual.aug',
:test_source => 'puppet:///modules/postfix/lenses/test_postfix_virtual.aug',
:stock_since => '1.0.0'
) }
end
require 'spec_helper'
describe 'postfix::mailman' do
end
require 'spec_helper'
describe 'postfix::mta' do
let (:facts) { {
:needs_postfix_class_with_params => true,
:osfamily => 'Debian',
} }
it { should contain_postfix__config('mydestination').with_value('bar') }
it { should contain_postfix__config('mynetworks').with_value('baz') }
it { should contain_postfix__config('relayhost').with_value('foo') }
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment