From ee4494ef95347cabe0d3c945d167f45d84a9fd2d Mon Sep 17 00:00:00 2001 From: "A. Karl Kornel" <akkornel@stanford.edu> Date: Tue, 23 Aug 2016 11:39:12 -0700 Subject: [PATCH] postfix::sender: New type --- manifests/postfix/sender.pp | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 manifests/postfix/sender.pp diff --git a/manifests/postfix/sender.pp b/manifests/postfix/sender.pp new file mode 100644 index 0000000..a60f721 --- /dev/null +++ b/manifests/postfix/sender.pp @@ -0,0 +1,48 @@ +# Many systems send emails "From" root@system-name. That causes problems when +# an email is bounced. This type is used to have Postfix change the sender +# address of an email while it is in flight. Both the From: header and the +# envelope sender are changed. +# +# Example of how to set a sender: +# +# base::postfix::sender { 'root@stanford.edu': +# ensure => 'noreply@stanford.edu' +# } +# +# Example of how to ensure there is no sender map: +# +# base::postfix::sender { 'luke': ensure => absent } +# +# Assumes that a command 'postmap hash:$file' has been defined that will +# rebuild the senders map. + +define base::postfix::sender( + $ensure, + $file = '/etc/postfix/senders' +) { + $pattern = "'^${name}'" + case $ensure { + 'absent': { + exec { "rm-sender-${name}": + command => "sed -i -e '/^${name}/d' ${file}", + onlyif => "grep ${pattern} ${file}", + notify => Exec["postmap hash:${file}"] + } + } + default: { + $line = "${name} ${ensure}" + exec { "add-sender-${name}": + command => "echo '${line}' >> ${file}", + unless => "grep ${pattern} ${file}", + require => Package['postfix'], + notify => Exec["postmap hash:${file}"], + } + exec { "fix-sender-${name}": + command => "sed -i -e 's/^${name}..*\$/${line}/' ${file}", + unless => "grep '^${line}\$' ${file}", + require => Exec["add-sender-${name}"], + notify => Exec["postmap hash:${file}"], + } + } + } +} -- GitLab