lib/custom_facts/util/parser.rb in facter-4.0.8.pre vs lib/custom_facts/util/parser.rb in facter-4.0.9.pre
- old
+ new
@@ -63,10 +63,21 @@
end
def parse_results
raise ArgumentError, 'Subclasses must respond to parse_results'
end
+
+ def parse_executable_output(output)
+ res = nil
+ begin
+ res = YAML.safe_load output
+ rescue Exception => e
+ Facter.debug("Could not parse executable fact output as YAML or JSON (#{e.message})")
+ end
+ res = KeyValuePairOutputFormat.parse output unless res.is_a?(Hash)
+ res
+ end
end
module KeyValuePairOutputFormat
def self.parse(output)
return {} if output.nil?
@@ -118,11 +129,11 @@
extension_matches?(filename, 'json')
end
class ScriptParser < Base
def parse_results
- KeyValuePairOutputFormat.parse LegacyFacter::Core::Execution.exec(quote(filename))
+ parse_executable_output(LegacyFacter::Core::Execution.exec(quote(filename)))
end
private
def quote(filename)
@@ -152,10 +163,10 @@
end
shell_command =
"\"#{powershell}\" -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File \"#{filename}\""
output = LegacyFacter::Core::Execution.exec(shell_command)
- KeyValuePairOutputFormat.parse(output)
+ parse_executable_output(output)
end
end
register(PowershellParser) do |filename|
LegacyFacter::Util::Config.windows? && extension_matches?(filename, 'ps1') && File.file?(filename)