Skip to content

Instantly share code, notes, and snippets.

Created Aug 7, 2012
What would you like to do?
Puppet::Parser::Functions::newfunction(:module_file, :type => :rvalue, :doc => "
Function module_file:
load file from relative or absolute path, relative path will search puppet modules files directory.
") do |args|
raise Puppet::ParseError, "module_file(): wrong number of arguments #{args.length}, expecting (filename)." if args.length != 1
raise Puppet::ParseError, "module_file(): does not accept empty file path." unless args[0]
file = args[0]
# Perform relative lookup in modules/files dir.
if file != File.expand_path(file)
env = Puppet[:environment]
mod_name, file = file.split(File::SEPARATOR, 2)
mod = Puppet::Module.find(mod_name, env)
raise Puppet::Error "module_file(): invalid module name #{mod_name}" unless mod
path = mod.path
file = File.join(path, "files", file)
result =
rescue Exception => e
raise Puppet::ParseError, "module_file(): failed to read #{file}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment