Commit 0b3d92ae authored by Karl Kornel's avatar Karl Kornel
Browse files

postfix::sender: Use file_line instead of exec for writing the line

parent a0f05978
...@@ -21,26 +21,26 @@ define base::postfix::sender( ...@@ -21,26 +21,26 @@ define base::postfix::sender(
$file = '/etc/postfix/senders' $file = '/etc/postfix/senders'
) { ) {
$pattern = "'^${name}'" $pattern = "'^${name}'"
$line = "${name} ${ensure}"
$file_line_ensure = $ensure ? {
'absent' => 'absent',
default => 'present',
}
file_line { "add-sender-${name}":
ensure => $file_line_ensure,
path => $file,
line => $line,
require => Package['postfix'],
notify => Exec["postmap hash:${file}"],
}
case $ensure { case $ensure {
'absent': {
exec { "rm-sender-${name}":
command => "sed -i -e '/^${name}/d' ${file}",
onlyif => "grep ${pattern} ${file}",
notify => Exec["postmap hash:${file}"]
}
}
default: { 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}": exec { "fix-sender-${name}":
command => "sed -i -e 's/^${name}..*\$/${line}/' ${file}", command => "sed -i -e 's/^${name}..*\$/${line}/' ${file}",
unless => "grep '^${line}\$' ${file}", unless => "grep '^${line}\$' ${file}",
require => Exec["add-sender-${name}"], require => File_line["add-sender-${name}"],
notify => Exec["postmap hash:${file}"], notify => Exec["postmap hash:${file}"],
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment