Skip to content

Instantly share code, notes, and snippets.

Created June 3, 2015 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9e8cd035216bbcb23ca7 to your computer and use it in GitHub Desktop.
Save anonymous/9e8cd035216bbcb23ca7 to your computer and use it in GitHub Desktop.
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment