Writing facts for Windows in Ruby

asked 2017-02-24 08:56:48 -0600

Hi, I'm working on fact for Windows that should display parameter "server" from puppet.conf file. I wrote this fact for Linux and there is no problem. There is a code:

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

It works perfectly. When I'm trying to do the same for Windows (when "Windows" || "windows" of course and another path for file) I get the facter message "custom fact resolved to Null". Trying figure it out I've noticed that facter don't load the content of file and the array is empty adn Foreman displays #<file:0x3eda308>. Does anyone know why? It is Windows Server 2003, facter version 3.1.1. Thanks, Emila.

edit retag flag offensive close merge delete