From 16b06320cd3bb3121446717c05b6bc13ae2ff133 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 27 Jul 2011 18:41:27 +0200 Subject: init of trocla module --- lib/puppet/util/trocla_helper.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/puppet/util/trocla_helper.rb (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/trocla_helper.rb b/lib/puppet/util/trocla_helper.rb new file mode 100644 index 0000000..8187d08 --- /dev/null +++ b/lib/puppet/util/trocla_helper.rb @@ -0,0 +1,31 @@ +module Puppet::Util::TroclaHelper + def trocla(trocla_func,has_options,*args) + # Functions called from puppet manifests that look like this: + # lookup("foo", "bar") + # internally in puppet are invoked: func(["foo", "bar"]) + # + # where as calling from templates should work like this: + # scope.function_lookup("foo", "bar") + # + # Therefore, declare this function with args '*args' to accept any number + # of arguments and deal with puppet's special calling mechanism now: + if args[0].is_a?(Array) + args = args[0] + end + + key = args[0] || raise(Puppet::ParseError, "You need to pass at least a key as an argument!") + format = args[1] || 'plain' + options = args[2] || {} + + configfile = File.join(File.dirname(Puppet.settings[:config]), "trocla.yaml") + + raise(Puppet::ParseError, "Trocla config file #{configfile} not readable") unless File.exist?(configfile) + raise(Puppet::ParseError, "You need rubygems to use Trocla") unless Puppet.features.rubygems? + + require 'rubygems' + require 'trocla' + + has_options ? Trocla.new(configfile).send(trocla_func, key, format, options) : Trocla.new(configfile).send(trocla_func, key, format) + end + module_function :trocla +end \ No newline at end of file -- cgit v1.2.3