diff --git a/manifests/config.pp b/manifests/config.pp index c8115a16431131117a9d17e9c1eef8feafa66446..d623ff6194068343a5d7fa6adafc114bbab95fc8 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -9,7 +9,7 @@ # === Parameters # # [*name*] - name of the parameter. -# [*ensure*] - present/absent. defaults to present. +# [*ensure*] - present/absent/blank. defaults to present. # [*value*] - value of the parameter. # # === Requires @@ -23,12 +23,20 @@ # value => 'yes', # } # -define postfix::config ($value, $ensure = present) { +# postfix::config { 'relayhost': +# ensure => 'blank', +# } +# +define postfix::config ($value = undef, $ensure = 'present') { - validate_string($value) validate_string($ensure) - validate_re($ensure, ['present', 'absent'], - "\$ensure must be either 'present' or 'absent', got '${ensure}'") + validate_re($ensure, ['present', 'absent', 'blank'], + "\$ensure must be either 'present', 'absent' or 'blank', got '${ensure}'") + if ($ensure == 'present') { + validate_string($value) + validate_re($value, '^.+$', + '$value can not be empty if ensure = present') + } if (!defined(Class['postfix'])) { fail 'You must define class postfix before using postfix::config!' @@ -51,6 +59,11 @@ define postfix::config ($value, $ensure = present) { changes => "rm ${name}", } } + blank: { + augeas { "blank postfix '${name}'": + changes => "clear ${name}", + } + } default: {} } } diff --git a/manifests/mta.pp b/manifests/mta.pp index 45d113fbff5e46a6c2bbed42013d18a2d9fae5cb..7df275ebb192db557dc67d61bd9edd2b778e753a 100644 --- a/manifests/mta.pp +++ b/manifests/mta.pp @@ -3,14 +3,16 @@ # This class configures a minimal MTA, delivering mail to # $mydestination. # -# A valid relay host is required ($relayhost) for outbound email. +# Either a valid relay host or the special word 'direct' is required +# ($relayhost) for outbound email. # # transport & virtual maps get configured and can be populated with # postfix::transport and postfix::virtual # # === Parameters # -# [*relayhost*] - (string) the relayhost to use +# [*relayhost*] - (string) the relayhost to use or 'direct' to send mail +# directly without a relay. # [*mydestination*] - (string) # [*mynetworks*] - (string) # @@ -36,10 +38,17 @@ class postfix::mta ( validate_re($mynetworks, '^\S+$', 'Wrong value for $mynetworks') + # If direct is specified then relayhost should be blank + if ($relayhost == 'direct') { + postfix::config { 'relayhost': ensure => 'blank' } + } + else { + postfix::config { 'relayhost': value => $relayhost } + } + postfix::config { 'mydestination': value => $mydestination; 'mynetworks': value => $mynetworks; - 'relayhost': value => $relayhost; 'virtual_alias_maps': value => 'hash:/etc/postfix/virtual'; 'transport_maps': value => 'hash:/etc/postfix/transport'; } diff --git a/spec/defines/postfix_config_spec.rb b/spec/defines/postfix_config_spec.rb index d166f1007e897793bc08b02476f47c845bec1319..886f8b0d374efe2289e13b4d56ea249db59a9cbb 100644 --- a/spec/defines/postfix_config_spec.rb +++ b/spec/defines/postfix_config_spec.rb @@ -11,7 +11,7 @@ describe 'postfix::config' do it 'should fail' do expect { should contain_augeas("set postfix 'foo'") - }.to raise_error(Puppet::Error, /Must pass value to Postfix::Config/) + }.to raise_error(Puppet::Error, /value can not be empty/) end end @@ -46,7 +46,7 @@ describe 'postfix::config' do it 'should fail' do expect { should contain_augeas("set postfix 'foo'") - }.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/) + }.to raise_error(Puppet::Error, /must be either 'present', 'absent' or 'blank'/) end end