Skip to content

Instantly share code, notes, and snippets.

@lak
Created December 8, 2009 00:06
Show Gist options
  • Select an option

  • Save lak/251275 to your computer and use it in GitHub Desktop.

Select an option

Save lak/251275 to your computer and use it in GitHub Desktop.
Puppet::Parser::Functions.newfunction :load_data, :type => :statement do |args|
if args.length == 1
klass = args[0]
else
klass = resource.title
end
datadir = "/Users/luke/git/clients/redhat/data"
dirs = datadir.split("/") + klass.split("::")
name = dirs.pop + ".yaml"
dir = dirs.join("/")
path = File.join(dir, name)
unless FileTest.exist?(path)
raise ArgumentError, "Could not find data file for class %s" % klass
end
params = YAML.load_file(path)
raise ArgumentError, "Data for %s is not a hash" % klass unless params.is_a?(Hash)
params.each do |param, value|
setvar(param, value)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment