Ask Your Question
0

Custom hash fact not working

asked 2015-06-03 13:26:03 -0500

tek0011 gravatar image

Can someone take a look at this? I have been working on it for far too long. Essentially I have written a custom hash fact. When I remove Facter.add it works fine, yet when I add the Facter.add and setcode I get nothing.

https://gist.github.com/anonymous/9e8cd035216bbcb23ca7

#This code works and when it gets to p modelshash - it prints out the entire hash as expected:
#{"qlogicmodel0"=>"QLE2562", "qlogicmodel1"=>"QLE2662", "qlogicmodel2"=>"QLE2662", "qlogicmodel3"=>"QLE2562"}

# require 'facter'

# models = Facter::Core::Execution.exec('qaucli -i | find "HBA Model"')
# modelshash = {}
# models.each_line.each_with_index do |line, index|
  # newmodels = Facter::Core::Execution.exec("qaucli -i #{index} | find \"HBA Model\"").split(':').last.strip
  # newmodels.split(/\n/).each do |pair|
    # key,value = pair.split(/\n/)
    # modelshash["qlogicmodel#{index}"] = key
  # end
# end
# p modelshash


# The code below now fails when calling Facter.add and setcode do - it will not return a fact of qlogicmodels with the above hash

require 'facter'

Facter.add("qlogicmodels") do
  setcode do
    models = Facter::Core::Execution.exec('qaucli -i | find "HBA Model"')
    modelshash = {}
    models.each_line.each_with_index do |line, index|
      newmodels = Facter::Core::Execution.exec("qaucli -i #{index} | find \"HBA Model\"").split(':').last.strip
      newmodels.split(/\n/).each do |pair|
        key,value = pair.split(/\n/)
        modelshash["qlogicmodel#{index}"] = key
      end
    end
    modelshash
  end
end

Thanks

edit retag flag offensive close merge delete

Comments

Please show the output of "facter qlogicmodels" when it fails. Do you get nothing back at all, or do you get a fact name with an empty hash, or something else?

GregLarkin gravatar imageGregLarkin ( 2015-06-05 13:37:17 -0500 )edit

Also, shall I assume you're running this on Windows, since you're using "find" instead of "grep"? If so, it's also a good practice to confine the fact to the operating system on which it will function.

GregLarkin gravatar imageGregLarkin ( 2015-06-05 13:38:43 -0500 )edit

@tek0011 update you question if you have additional commentary. This isn't a forum, it's a Q&A site.

ramindk gravatar imageramindk ( 2015-06-06 08:16:34 -0500 )edit

Thanks for your replies, I was out of town without internet.

tek0011 gravatar imagetek0011 ( 2015-06-09 06:57:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-06-09 06:58:11 -0500

tek0011 gravatar image

This was a Facter path issue. For someone reason on my two test servers the gems/ruby/facter paths got set to totally different environments. I moved to a few other servers and everything worked fine. Went back to original servers with the issue and fixed their environments.

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

1 follower

Stats

Asked: 2015-06-03 13:26:03 -0500

Seen: 352 times

Last updated: Jun 09 '15