Commit 2b8b59ad authored by Raphaël Pinson's avatar Raphaël Pinson
Browse files

Replace common::line with augeas in the postfix::transport. Modify the mailman...

Replace common::line with augeas in the postfix::transport. Modify the mailman and avocatsch modules with new destination syntax.
parent dbf5005c
(*
Module: Postfix_Transport
Parses /etc/postfix/transport
Author: Raphael Pinson <raphael.pinson@camptocamp.com>
About: Reference
This lens tries to keep as close as possible to `man 5 transport` where possible.
About: License
This file is licenced under the LGPL v2+, like the rest of Augeas.
About: Lens Usage
To be documented
About: Configuration files
This lens applies to /etc/postfix/transport. See <filter>.
About: Examples
The <Test_Transport> file contains various examples and tests.
*)
module Postfix_Transport =
autoload xfm
(* View: space_or_eol *)
let space_or_eol = del /([ \t]*\n)?[ \t]+/ " "
(* View: colon *)
let colon = Sep.colon
(* View: transport *)
let transport = [ label "transport" . (store Rx.word)? ]
(* View: nexthop *)
let nexthop = [ label "nexthop" . (store Rx.space_in)? ]
(* View: record *)
let record = [ label "pattern" . store /[A-Za-z0-9@\*.-]+/
. space_or_eol . transport
. colon . nexthop
. Util.eol ]
(* View: lns *)
let lns = (Util.empty | Util.comment | record)*
(* Variable: filter *)
let filter = incl "/etc/postfix/transport"
. incl "/etc/postfix/virtual"
let xfm = transform lns filter
(*
Module: Test_Postfix_Transport
Provides unit tests and examples for the <Postfix_Transport> lens.
*)
module Test_Postfix_Transport =
(* View: conf *)
let conf = "# a comment
the.backed-up.domain.tld relay:[their.mail.host.tld]
.my.domain :
* smtp:outbound-relay.my.domain
example.com uucp:example
example.com slow:
example.com :[gateway.example.com]
user.foo@example.com
smtp:bar.example:2025
.example.com error:mail for *.example.com is not deliverable
"
(* Test: Postfix_Transport.lns *)
test Postfix_Transport.lns get conf =
{ "#comment" = "a comment" }
{ "pattern" = "the.backed-up.domain.tld"
{ "transport" = "relay" }
{ "nexthop" = "[their.mail.host.tld]" } }
{ "pattern" = ".my.domain"
{ "transport" }
{ "nexthop" } }
{ "pattern" = "*"
{ "transport" = "smtp" }
{ "nexthop" = "outbound-relay.my.domain" } }
{ "pattern" = "example.com"
{ "transport" = "uucp" }
{ "nexthop" = "example" } }
{ "pattern" = "example.com"
{ "transport" = "slow" }
{ "nexthop" } }
{ "pattern" = "example.com"
{ "transport" }
{ "nexthop" = "[gateway.example.com]" } }
{ "pattern" = "user.foo@example.com"
{ "transport" = "smtp" }
{ "nexthop" = "bar.example:2025" } }
{ "pattern" = ".example.com"
{ "transport" = "error" }
{ "nexthop" = "mail for *.example.com is not deliverable" } }
class postfix::augeas {
augeas::lens {'postfix_transport':
ensure => present,
lens_source => 'puppet:///modules/postfix/lenses/postfix_transport.aug',
test_source => 'puppet:///modules/postfix/lenses/test_postfix_transport.aug',
}
}
......@@ -31,12 +31,37 @@
# }
# }
#
define postfix::transport ($destination, $ensure='present') {
common::line {"${name} ${destination}":
ensure => $ensure,
file => '/etc/postfix/transport',
line => "${name} ${destination}",
notify => Exec['generate /etc/postfix/transport.db'],
require => Package['postfix'],
define postfix::transport (
$destination,
$file='/etc/postfix/transport',
$ensure='present'
) {
include postfix::augeas
case $ensure {
'present': {
$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 transport - ${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/transport.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