Created
February 24, 2017 18:11
-
-
Save hlindberg/796d25e3290d0a6d6bc3876168cb83fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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