Skip to content

Instantly share code, notes, and snippets.

@glennsarti
Last active May 2, 2017 18:32
Show Gist options
  • Save glennsarti/285e14edc84d53a423b19d971138f7a5 to your computer and use it in GitHub Desktop.
Save glennsarti/285e14edc84d53a423b19d971138f7a5 to your computer and use it in GitHub Desktop.
Quick and dirty custom facts for parsing a file
infospot_file = "C:/Source/testmodule/infospot.properties"
Facter.add('infospot_site') do
confine :osfamily => :windows
setcode do
begin
return unless File.exist?(infospot_file)
value = nil
File.open(infospot_file, "r") do |f|
f.each_line do |line|
kv = line.strip.split(/=/,2)
value = kv[1] if kv[0] == "site"
end
end
value
rescue
end
end
end
Facter.add('infospot_description') do
confine :osfamily => :windows
setcode do
begin
return unless File.exist?(infospot_file)
value = nil
File.open(infospot_file, "r") do |f|
f.each_line do |line|
kv = line.strip.split(/=/,2)
value = kv[1] if kv[0] == "description"
end
end
value
rescue
end
end
end
Facter.add('infospot_customer') do
confine :osfamily => :windows
setcode do
begin
return unless File.exist?(infospot_file)
value = nil
File.open(infospot_file, "r") do |f|
f.each_line do |line|
kv = line.strip.split(/=/,2)
value = kv[1] if kv[0] == "customer"
end
end
value
rescue
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment