#!/usr/bin/ruby module Puppet::Parser::Functions newfunction(:template_with_check, :type => :rvalue) do |args| tmpl = args[0] checkscript = args[1] # tmpfile = generate("mktemp /tmp/template.XXXXXX") tmpfile = File.new("/tmp/template.tmp", 'w+') # Retrieve the internal method name method_template = Puppet::Parser::Functions.function(:template) # Call it with the template name content = send(method_template, tmpl) # Test content in a temporary file tmpfile.write(content) tmpfile.close checkcmd=checkscript+" "+tmpfile.path system(checkcmd) File.delete(tmpfile.path) if $?==0 return(content) end raise Puppet::ParseError, "could not validate content with command "+checkscript end end