Ask Your Question

Custom fact depends on gem installed by class

asked 2014-04-04 08:25:14 -0600

kidrock gravatar image

updated 2014-04-04 16:48:48 -0600

ffrank gravatar image

I have a few custom facts, written in Ruby, that need an XML parser (XmlSimple) - so there is a line that says "require 'xmlsimple'". This is a problem because that gem is supposed to be installed by a class which of course runs after the facts are loaded. It can't get that far because the puppet run fails with this:

Error: Could not retrieve local facts: cannot load such file -- xmlsimple Error: Failed to apply catalog: Could not retrieve local facts: cannot load such file -- xmlsimple

What is the best way to work around this? I'm hoping to ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-04-04 16:47:35 -0600

ffrank gravatar image

updated 2014-04-07 02:58:42 -0600

You can catch that exception.

setcode do
    require 'xmlsimple'
  rescue Exception => ex
    Puppet.warning ex.message

This way, if the require does fail, your fact will just assume the empty value.

Edit: It will also add the error message to the agent output as a warning.

edit flag offensive delete link more


I don't like the idea of swallowing the exception (what if the file fails to load for some reason in the future? I would want to know about it ...(more)

kidrock gravatar imagekidrock ( 2014-04-06 17:57:18 -0600 )edit

Right, the error may be of interest. I will edit the answer to make it include a warning with the exception message. This is all untested and may need further ...(more)

ffrank gravatar imageffrank ( 2014-04-07 02:57:04 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-04-04 08:25:14 -0600

Seen: 403 times

Last updated: Apr 07 '14