Skip to content

Instantly share code, notes, and snippets.

@glarizza
Created December 1, 2010 22:02
Show Gist options
  • Save glarizza/724312 to your computer and use it in GitHub Desktop.
Save glarizza/724312 to your computer and use it in GitHub Desktop.
# This code leaves me with a hash of values called h
h = {}
File.open("/etc/facts.txt") do |fp|
fp.each do |line|
key, value = line.chomp.split("=")
h[key] = value
end
end
# If I want to return values as a hash in an MC Agent, THIS works:
reply[:huron_class] = h["huron_class"]
reply[:environment] = h["environment"]
# OUTPUT:
#bash-3.2# mc-rpc --agent etc_facts --action remove --arg removevar="shel" --arg keyvalue="huron_class" -v
#Determining the amount of hosts matching filter for 2 seconds .... 1
#
# * [ ============================================================> ] 1 / 1
#
#
#boe : OK
# {:environment=>"production", :huron_class=>"staff"}
#
#---- etc_facts#remove call stats ----
# Nodes: 1 / 1
# Pass / Fail: 1 / 0
# Start Time: Wed Dec 01 16:56:13 -0500 2010
# Discovery Time: 2000.79ms
# Agent Time: 9.32ms
# Total Time: 2010.11ms
# This does not:
h.each{|key, value| reply[h[key]] = h[value]}
# OUTPUT
#bash-3.2# mc-rpc --agent etc_facts --action remove --arg removevar="shel" --arg keyvalue="huron_class" -v
#Determining the amount of hosts matching filter for 2 seconds .... 1
#
# * [ ============================================================> ] 1 / 1
#
#
#boe : OK
# {"staff"=>nil, "production"=>nil}
#
#---- etc_facts#remove call stats ----
# Nodes: 1 / 1
# Pass / Fail: 1 / 0
# Start Time: Wed Dec 01 17:00:33 -0500 2010
# Discovery Time: 2000.73ms
# Agent Time: 10.15ms
# Total Time: 2010.89ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment