Please review pull request #23: (#13684) Add safe_hiera function that accepts defaults opened by (eshamow)

Description:

Adds a :safe_heira function that accepts safe_hiera('key','default') and
returns default even if hiera is misconfigured. It allows hiera to fail
and passes through the error message if no default is defined.

  • Opened: Mon Apr 09 00:04:53 UTC 2012
  • Based on: puppetlabs:master (54be04bb999004d34f19a0482299d017556604af)
  • Requested merge: eshamow:tickets/feature/13684_add_safe_hiera_function (344d0147f80d879f4f7323af2d57cc38937014ba)

Diff follows:

diff --git a/lib/puppet/parser/functions/safe_hiera.rb b/lib/puppet/parser/functions/safe_hiera.rb
new file mode 100644
index 0000000..aede6c5
--- /dev/null
+++ b/lib/puppet/parser/functions/safe_hiera.rb
@@ -0,0 +1,24 @@
+#
+# safe_hiera.rb
+#
+
+module Puppet::Parser::Functions
+  newfunction(:safe_hiera, :type => :rvalue, :doc => <<-EOS
+Calls hiera, but fails gracefully if hiera is misconfigured.
+    EOS
+  ) do |arguments|
+
+    if arguments[1]
+      begin
+        function_hiera(arguments[0])
+      rescue
+        arguments[1]
+      end
+    else
+      function_hiera(arguments[0])
+    end
+
+  end
+end
+
+# vim: set ts=2 sw=2 et :

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to