我试图用Ruby在Windows上为Puppet写一个事实。事实应该显示puppet.conf
文件中的服务器参数的值。这是非常简单的代码,在Linux上运行良好。它也应该在Windows上使用更改的文件路径,但是facter将其解析为null。问题是,因为没有打开文件,我完全不知道为什么。这是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
在Windows上,它应该与内核值和文件路径相同。有谁知道为什么facter没有打开文件?
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
如果它是重要信息,它在Windows 2003上。