Skip to content

Instantly share code, notes, and snippets.

@ripienaar
Last active December 16, 2015 13:28
Show Gist options
  • Save ripienaar/59018d7c084059e776f2 to your computer and use it in GitHub Desktop.
Save ripienaar/59018d7c084059e776f2 to your computer and use it in GitHub Desktop.
create_resources("mail::domain", $domains)
{
"relay_domains": {
"x.net": {
"nexthop": "70.x.x.x",
"spamdestination": "rip@devco.net",
"spamthreshold": 1500,
"enable_antispam": 1
},
"x.co.uk": {
"nexthop": "70.x.x.x",
"spamdestination": "rip@devco.net",
"spamthreshold": 1500,
"enable_antispam": 1
},
}
$names = keys($domains)
mail::domains($names: domains => $domains}
define mail::domains($domains) {
$domain = $domains[$name]
mail::domain{$name:
nexthop => $domain["nexthop"]
.
.
}
}
$domains.each |$name, $domain| {
mail::domain{$name:
nexthop => $domain["nexthop"]
.
.
}
}
each($domains) |$name, $domain| {
# see https://docs.puppetlabs.com/puppet/4.2/reference/lang_resources_advanced.html#setting-attributes-from-a-hash
mail::domain{$name:
* => $domain
}
}
$defaults = {
"spamthreshold" => 1500,
"enable_antispam" => 1
}
$domains.each |$name, $domain| {
# see https://docs.puppetlabs.com/puppet/4.2/reference/lang_resources_advanced.html#setting-attributes-from-a-hash
mail::domain{$name:
* => $defaults + $domain # + now merge hashes
}
}
$defaults = {
"spamthreshold" => 1500,
"enable_antispam" => 1
}
$domains.each |$name, $domain| {
mail::domain{
default:
* => $defaults;
$name:
* => $domain
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment