Skip to content

Instantly share code, notes, and snippets.

@purplexa
Created May 13, 2017 04:12
Show Gist options
  • Save purplexa/014fa9eaebf58022a10e787b22904fa9 to your computer and use it in GitHub Desktop.
Save purplexa/014fa9eaebf58022a10e787b22904fa9 to your computer and use it in GitHub Desktop.
metaparameters on hiera-defined resources
class foobar (
Hash[String,
Struct[{
attributes => Hash[String, Data],
Optional[requires] => Hash[String, String],
Optional[notifies] => Hash[String, String]
}]] $files,
Hash[String, Data] $file_defaults = {},
) {
$files.each |$key, $value| {
$requires = $value['requires'].reduce([]) |$memo, $x| { $memo + [Resource[$x[0]][$x[1]]] }
$notifies = $value['notifies'].reduce([]) |$memo, $x| { $memo + [Resource[$x[0]][$x[1]]] }
file {
$key:
* => $value['attributes'],
require => $requires,
notify => $notifies,
;
default:
* => $file_defaults,
;
}
}
}
---
foobar::files:
'/etc/foo':
attributes:
ensure: 'file'
owner: 'root'
group: 'root'
mode: '0640'
requires:
package: 'foo'
notifies:
service: 'foo'
'/etc/bar':
attributes:
ensure: 'directory'
owner: 'bar'
group: 'bar'
mode: '0750'
'/etc/bar/bar.conf':
attributes:
ensure: 'file'
owner: 'bar'
group: 'bar'
mode: '0640'
requires:
package: 'bar'
notifies:
service: 'bar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment