Commit 381eb9ad authored by Raphaël Pinson's avatar Raphaël Pinson
Browse files

Use augeas instead of common::line in postfix::virtual

parent a0e06594
......@@ -11,7 +11,7 @@
#- Class["postfix"]
#- Postfix::Hash["/etc/postfix/virtual"]
#- Postfix::Config["virtual_alias_maps"]
#- common::line (from module common)
#- augeas
#
#Example usage:
#
......@@ -19,24 +19,59 @@
#
# include postfix
#
# postfix::hash { "/etc/postfix/virtual":
# postfix::hash { "/etc/postfix/transport":
# ensure => present,
# }
# postfix::config { "virtual_alias_maps":
# value => "hash:/etc/postfix/virtual"
# postfix::config { "transport_maps":
# value => "hash:/etc/postfix/transport"
# }
# postfix::virtual { "user@example.com":
# postfix::transport { "mailman.example.com":
# ensure => present,
# destination => "root",
# destination => "mailman",
# }
# }
#
define postfix::virtual ($destination, $ensure = 'present') {
common::line {"${name} ${destination}":
ensure => $ensure,
file => '/etc/postfix/virtual',
line => "${name} ${destination}",
notify => Exec['generate /etc/postfix/virtual.db'],
require => Package['postfix'],
define postfix::virtual (
$destination,
$nexthop='',
$file='/etc/postfix/virtual',
$ensure='present'
) {
include postfix::augeas
case $ensure {
'present': {
if ($nexthop) {
$changes = [
"set pattern[. = '${name}'] '${name}'",
"set pattern[. = '${name}']/transport '${destination}'",
# TODO: support nexthop
"set pattern[. = '${name}']/nexthop '${nexthop}'",
]
} else {
$changes = [
"set pattern[. = '${name}'] '${name}'",
"set pattern[. = '${name}']/transport '${destination}'",
# TODO: support nexthop
"clear pattern[. = '${name}']/nexthop",
]
}
}
'absent': {
$changes = "rm pattern[. = '${name}']"
}
default: {
fail("Wrong ensure value: ${ensure}")
}
}
augeas {"Postfix virtual - ${name}":
load_path => '/usr/share/augeas/lenses/contrib/',
context => "/files${file}",
changes => $changes,
require => [Package['postfix'], Augeas::Lens['postfix_transport']],
notify => Exec['generate /etc/postfix/virtual.db'],
}
}
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