Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hlindberg
Created February 24, 2017 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlindberg/796d25e3290d0a6d6bc3876168cb83fb to your computer and use it in GitHub Desktop.
Save hlindberg/796d25e3290d0a6d6bc3876168cb83fb to your computer and use it in GitHub Desktop.
Puppet::Parser::Functions.newfunction(:default_content,
:type => :rvalue,
:doc => <<-'ENDOFDOC'
Takes an optional content and an optional template name and returns the
contents of a file.
Examples:
$config_file_content = default_content($file_content, $template_location)
file { '/tmp/x':
ensure => 'file',
content => $config_file_content,
}
ENDOFDOC
) do |args|
content = args[0]
template_name = args[1]
emptyish = lambda { |x| x.nil? || x.empty? || x == :undef }
return content unless emptyish.call(content)
return call_function('template', template_name) unless emptyish.call(template_name)
return :undef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment