Ask Your Question

Custom fact is always empty

asked 2013-06-22 13:25:27 -0500

updated 2013-06-22 13:25:57 -0500

I have the following Ruby file (medialibraryhost.rb) in my module's lib/facter directory:

Facter.add(:media_library_host) do
  confine :kernel => :linux
  setcode do
    Facter::Util::Resolution.exec('if [ -e "/etc/" ] ; then cat /etc/ ; fi')

Basically it reads host line from a file. But no matter what I put in that file whenever I try to use $::media_library_host fact in my manifests it is empty. Any clues?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-06-22 13:54:53 -0500

domcleal gravatar image

Facter's exec method is designed to run commands it can find in PATH, not arbitrary shell code. You could do this instead:

Facter::Util::Resolution.exec('cat /etc/') if File.exist?('/etc/')

Or better:'/etc/') if File.exist?('/etc/')

Or perhaps best, if you're exclusively on Facter 1.7, since it transparently handles the file being missing:'/etc/')

(add require 'facter/util/file_read' to the top of your source file too)

edit flag offensive delete link more


Thanks it worked. Though eventually I ended up using this:'/etc/') {|f| f.readline.chomp} if File.exist?('/etc/')

Andrey Adamovich gravatar imageAndrey Adamovich ( 2013-06-22 17:15:20 -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


Asked: 2013-06-22 13:25:27 -0500

Seen: 651 times

Last updated: Jun 22 '13