Skip to content

Instantly share code, notes, and snippets.

@richardc
Created April 26, 2012 16:29
Show Gist options
  • Save richardc/2500795 to your computer and use it in GitHub Desktop.
Save richardc/2500795 to your computer and use it in GitHub Desktop.
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