Last active
May 2, 2017 18:32
-
-
Save glennsarti/285e14edc84d53a423b19d971138f7a5 to your computer and use it in GitHub Desktop.
Quick and dirty custom facts for parsing a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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