Skip to content

Instantly share code, notes, and snippets.

@jeffmccune
Created January 6, 2012 21:44
Show Gist options
  • Save jeffmccune/1572535 to your computer and use it in GitHub Desktop.
Save jeffmccune/1572535 to your computer and use it in GitHub Desktop.
Style Guide 11.9
# = motd class
#
# A Hierarchy of Class Param Value => Node Param Value => Module Default Value
#
# WITHOUT _real and UNSET ugliness! Hooray!
# ... but WITH inherits! Boo..?
#
# The class param value part of the hierarchy happens here since this is a parameterized class.
# The node param value and module default part of the hierarchy happens in params class
# we're inheriting from.
#
class motd (
$banner_content = $::motd::params::banner_content,
$banner_source = $::motd::params::banner_source,
) inherits motd::params {
file { '/etc/motd':
owner => 0,
group => 0,
mode => 0644,
content => $banner_content,
source => $banner_source,
}
}
class motd::params {
# The Node param value and Module default part of the hierarchy happens here
# The undef key is the module default value and
# the default key is the node param value. Neither of these are used if the class parameter value
# is specified.
$banner_content = $::motd_banner_content ?
undef => 'THUG LIFE (Whatever the heck that means... This is the module default value.)',
default => $::motd_banner_content,
}
$banner_source = $::motd_banner_source ?
undef => undef,
default => $::motd_banner_source,
}
# We should probably make sure the user doesn't specify both... But we don't because we're lazy.
}
# Use cases
# Simple case (puppet apply -e 'include motd')
include motd
# Simple case with customization
# puppet apply -e 'class { motd: banner_content => "Puppet: $puppetversion" }'
# Puppet Enterprise Console
node default {
$motd_banner_content = "This variable could have been set in the GUI"
# The GUI could have included the class for us as well!
include motd
}
# Use our own file _without_ Puppet Enterprise
node default {
class { motd:
banner_source => "puppet:///sitefiles/motd.erb",
banner_content => undef,
}
}
# Use our own file WITH Puppet Enterprise Console
# Both the class and the variables can be set using the GUI
node default {
$motd_banner_content => undef
$motd_banner_source => "puppet:///sitefiles/motd.erb"
include motd
}
# EOF
@jeffmccune
Copy link
Author

There's one bug where you still have no way to differentiate between $motd_banner_content as a node parameter being explicitly set to undef or being implicitly not set.

I think we could work around this in motd::params by just always setting $banner_content to undef is $banner_source is defined by the user somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment