0

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.

mila002
  • 327
  • 3
  • 14
  • Where is your code for attemtpting this in Windows? – Matthew Schuchard Feb 25 '17 at 17:23
  • I've edited question, thanks. – mila002 Feb 25 '17 at 19:02
  • 1
    According to the documentation the normal location is `C:\ProgramData\PuppetLabs\puppet\etc\puppet.conf` in Windows. Your preceding directories appear different. – Matthew Schuchard Feb 25 '17 at 21:18
  • Yes, on Windows 2008 and higher, on Windows 2003 there is no Program Data folder so the directory is different. – mila002 Feb 27 '17 at 05:45
  • 1
    If the problem is indeed that Facter fails to open the file, then there are really only two possibilities: (1) the name and/or path is incorrect, or (2) Facter does not have sufficient permissions to open the file. With respect to the latter, it is possible that the Facter process needs permissions not just on the file itself, but on all the directories in the path to it. – John Bollinger Feb 27 '17 at 16:58

0 Answers0