Skip to content

Instantly share code, notes, and snippets.

@danshultz
Created May 9, 2013 17:59
Show Gist options
  • Select an option

  • Save danshultz/5549265 to your computer and use it in GitHub Desktop.

Select an option

Save danshultz/5549265 to your computer and use it in GitHub Desktop.
I'm using a custom ENC which we are using to dump a yaml file based on an internal configuration wrapper. I want the ability to specify a parameter (variable) in the top scope and allow it to be be a default variable of a class. At this point, my research shows me this is not a bad idea
classes:
rsyslog::client:
port: 1234
parameters:
server: my-rsyslog-server
# This patterns supports defaulting a class scoped variable to the first scope level variable it comes across.
# If I wanted to explicitly check only the top level scope, I would do $::server
class rsyslog::client(
$server => $server, # $server = $server || undef
$port => $port ? { # $port = $port || '514'
'' => '514',
default => $port
}
) {
if !defined($server) { fail "server must be defined" }
notify { "The server is ${server}": }
notify { "The port is ${port}": }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment