Created
April 26, 2012 16:29
-
-
Save richardc/2500795 to your computer and use it in GitHub Desktop.
This file contains 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
module Puppet::Parser::Functions | |
require 'erb' | |
newfunction(:multitemplate, :type => :rvalue) do |args| | |
contents = nil | |
environment = compiler.environment | |
sources = args | |
sources.each do |file| | |
Puppet.debug("Looking for #{file} in #{environment}") | |
if filename = Puppet::Parser::Files.find_template(file, environment) | |
wrapper = Puppet::Parser::TemplateWrapper.new(self) | |
wrapper.file = file | |
begin | |
contents = wrapper.result | |
rescue => detail | |
raise Puppet::ParseError, "Failed to parse template %s: %s" % [file, detail] | |
end | |
break | |
end | |
end | |
raise Puppet::ParseError, "multitemplate: No match found for files: #{sources.join(', ')}" if contents == nil | |
contents | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment