I'm trying to write a fact for Puppet on Windows in Ruby. The fact should display the value of a server parameter from the puppet.conf
file. This is very simple code and works perfectly on Linux. It should also work on Windows with a changed path for the file, but facter resolves it to null. The problem is that facter doesn't open a file and I completely don't know why. Here is the code for Linux
Facter.add(:puppet_master) do
setcode do
puppet_master = ""
case Facter.value(:kernel)
when "Linux" || "linux"
conf_array = []
conf_array = File.open("/etc/puppetlabs/puppet/puppet.conf", "r").each_line.grep(/^server =/)
puppet_server_temp = conf_array.map! { |item| item.to_s}.join
arr = []
arr = puppet_server_temp.split(/=\s/)
puppet_master = arr[1]
puppet_master
end
end
end
On Windows it should be the same except kernel value and the file path. Does anyone know why facter doesn't open the file?
Code on Widnows
Facter.add(:puppet_master) do
setcode do
puppet_master = ""
case Facter.value(:kernel)
when "windows" || "Windows"
conf_array = []
conf_array = File.open("C:/Documents and Settings/All Users/Application Data/PuppetLabs/puppet/etc/puppet.conf", "r").each_line.grep(/^server =/)
puppet_server_temp = conf_array.map! { |item| item.to_s}.join
arr = []
arr = puppet_server_temp.split(/=\s/)
puppet_master = arr[1]
puppet_master
end
end
end
It's on Windows 2003 if it is important information.