Ask Your Question

Can a custom fact have a puppet class as a requirement before running?

asked 2013-05-02 08:32:16 -0500

Luke gravatar image

I want to run a custom fact that kicks off a shell script e.g.

Facter.add("myawesomescript") do setcode do Facter::Util::Resolution.exec('/root/') end end

Thing is that doesn't exist and I want puppet to place it.

Could I have a separate module that kicks off a class before anything in the module that has the facter lib stuff? It seems like facter is completely separate from puppet and kicks off right away. Just trying to think of a way around this.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-05-02 08:47:59 -0500

During a puppet run the plugins (incl custom facts) are pushed to the agent. Afterwards the facts are collected and returned to the master and the catalog is compiled. As the distribution and collection of facts is completed before the catalog is build you cannot depend on a script which will be part of the catalog.

Hope this helps

edit flag offensive delete link more


Thank you this is exactly what I thought. I basically want to pull a random value from /dev/urandom and store it as a fact. The thing is however is ...(more)

Luke gravatar imageLuke ( 2013-05-02 08:56:45 -0500 )edit

What are you trying to accomplish with that fact? Are you looking for something like a unique machine identifier?

Daniel gravatar imageDaniel ( 2013-05-02 09:03:40 -0500 )edit

Something like that.. I figured it out I will just run the fact like this:

/bin/bash -c "if [ -f /root/randomgen.result ]; then cat /root/randomgen.result; else cat ...(more)

Luke gravatar imageLuke ( 2013-05-02 09:50:18 -0500 )edit

Ok cool. could you mark the question as answered?

Daniel gravatar imageDaniel ( 2013-05-02 10:15:12 -0500 )edit

Here you go. Sorry didn't see the check thing.

Luke gravatar imageLuke ( 2013-05-02 11:06:45 -0500 )edit

answered 2013-05-02 17:10:42 -0500

Stefan gravatar image

in addition to Daniel's answer you can also

  1. Implement the shell script in pure ruby. SecureRandom may help you out
  2. Drop your shell script in the same directory as your custom fact. It should be pluginsynced together with your fact and inside your fact use Facter::Util::Resolution.exec(File.join(File.dirname(__FILE__), ''))
  3. Use external facts which was added in 1.7

Personally I'd prefer the first one but the others should work as well.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2013-05-02 08:32:16 -0500

Seen: 735 times

Last updated: May 02 '13