Ask Your Question
0

Why Custom Facts always empty ?

asked 2013-09-22 01:56:45 -0600

louyunfeng gravatar image

updated 2013-09-22 02:25:32 -0600

I create a python version fact in my module 'python'. But this fact always return nil (have already installed python). But it will work when I try Facter::Util::Resolution.exec('ruby --version'). I can not find the reason. Hope somebody help me . Thanks.

Facter.add(:python_version) do
       setcode do
              Facter::Util::Resolution.exec('python --version')
       end
end
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-09-22 03:06:20 -0600

updated 2013-09-22 03:25:32 -0600

Stefan gravatar image

Ah ! Got it... Trick is the output from python version is not on standard but on error...

Edit /tmp/facts/python_version.rb

Facter.add(:python_version) do
  setcode do
    Facter::Util::Resolution.exec('python --version  2>&1')
  end
end

Test it :

$ FACTERLIB=/tmp/facts/ facter python_version
Python 2.7.4

Cut or awk to get just the version, ie :

Facter.add(:python_version) do
  setcode do
    Facter::Util::Resolution.exec('python --version 2>&1 | cut -d " " -f 2')
  end
end

-- > 2.7.4

Warning it depends on the python you have in your path, to make it explicit, you should use

/usr ...
(more)
edit flag offensive delete link more

Comments

Thank you very much! It works correctly now. So happy! I use 'match(/\d+\.\d+\.\d+/).to_s' to get the just version. Your method also works. Thanks again!

louyunfeng gravatar imagelouyunfeng ( 2013-09-22 04:31:24 -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

Stats

Asked: 2013-09-22 01:56:45 -0600

Seen: 354 times

Last updated: Sep 22 '13