Ask Your Question
0

Custom fact depends on gem installed by class

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

kidrock gravatar image

updated 2014-04-04 16:48:48 -0500

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
1

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

ffrank gravatar image

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

You can catch that exception.

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

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

Comments

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 -0500 )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 -0500 )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

Stats

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

Seen: 272 times

Last updated: Apr 07 '14