Ask Your Question
0

Cant make a fact to work properly

asked 2013-11-29 05:48:17 -0500

csdenboer gravatar image

I'm trying to make a fact that returns something if the server has an external ip address. I made the following fact:

Facter.add(:hasexternalip) do
setcode do
    Facter::Util::Resolution.exec('(ifconfig | grep "inet addr:" | cut -d: -f2 | awk \'{ print $1}\' | grep -m 1 "194.140.246" ) || ( ifconfig | grep "inet addr:" | cut -d: -f2 | awk \'{ print $1}\' | grep -m 1 "91.215" )')
end
end

When I run the command in my shell I get my external ip as output (91.215.X.XX), but cant get it to load a fact. I have run

facter hasexternalip.rb
facter ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-11-29 07:14:17 -0500

Stefan gravatar image

updated 2013-11-30 06:32:45 -0500

Make sure the custom fact is placed in the correct directory. It should be in <module_path>/<your_module>/lib/facter/hasexternalip.rb. Then make sure you run the puppet agent at least once with --pluginsync. Then facter --debug --puppet hasexternalip should mention your fact.

Please note that the Facter::Util::Resolution.exec method is not designed to run arbitrary shell code. It expects to get only /path/to/command argument1 argument2... and no pipes and stuff, so consider to do something like

require 'ipaddr'
require 'facter/util/ip'

Facter.add(:hasexternalip) do
  setcode do
    external_networks = [
      IPAddr.new('194.140.246.0 ...
(more)
edit flag offensive delete link more
0

answered 2013-11-29 07:45:23 -0500

csdenboer gravatar image

Thanks for your reply, this code will not work when there are several IP addresses bound to 1 interface right?

edit flag offensive delete link more

Comments

If you have a questions about an answer, please use the comment function. I have updates my previous anwer that should work with multiple addresses on the same interface.

Stefan gravatar imageStefan ( 2013-11-30 06:06:38 -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: 2013-11-29 05:48:17 -0500

Seen: 190 times

Last updated: Nov 30 '13