Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -21,26 +21,26 @@ define base::postfix::sender(
$file = '/etc/postfix/senders'
) {
$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 {
'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}"],
require => File_line["add-sender-${name}"],
notify => Exec["postmap hash:${file}"],
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment