Codebase list facter / e056b44
(#21738) Revert "(#2157) Remove support for executable external facts on Windows" This reverts commit 008cc6cdf79df1589c060e2a088caffc9cf6da77. Conflicts: lib/facter/util/directory_loader.rb lib/facter/util/parser.rb Rob Reynolds 10 years ago
2 changed file(s) with 36 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
00 # A Facter plugin that loads external facts.
11 #
22 # Default Unix Directories:
3 # /etc/facter/facts.d, /etc/puppetlbas/facter/facts.d
3 # /etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"
44 #
55 # Default Windows Direcotires:
66 # C:\ProgramData\Puppetlabs\facter\facts.d (2008)
124124 end
125125
126126 register(ScriptParser) do |filename|
127 if not Facter::Util::Config.is_windows?
128 File.executable?(filename) && File.file?(filename)
127 if Facter::Util::Config.is_windows?
128 extension_matches?(filename, %w{bat com exe})
129 else
130 File.executable?(filename)
129131 end
130132 end
131133
134 # Executes and parses the key value output of Powershell scripts
135 #
136 # Before you can run unsigned ps1 scripts it requires a change to execution
137 # policy:
138 #
139 # Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
140 # Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
141 #
142 class PowershellParser < Base
143 # Returns a hash of facts from powershell output
144 def results
145 shell_command = "powershell -File #{filename}"
146 output = Facter::Util::Resolution.exec(shell_command)
132147
148 result = {}
149 output.split("\n").each do |line|
150 if line =~ /^(.+)=(.+)$/
151 result[$1] = $2
152 end
153 end
154
155 result
156 rescue Exception => e
157 Facter.warn("Failed to handle #{filename} as powershell facts: #{e.class}: #{e}")
158 Facter.debug(e.backtrace.join("\n\t"))
159 end
160 end
161
162 register(PowershellParser) do |filename|
163 Facter::Util::Config.is_windows? && extension_matches?(filename, "ps1")
164 end
165
133166 # A parser that is used when there is no other parser that can handle the file
134167 # The return from results indicates to the caller the file was not parsed correctly.
135168 class NothingParser