[Pkg-puppet-devel] [facter] 46/61: (#21738) Revert "(#2157) Remove support for executable external facts on Windows"

Stig Sandbeck Mathisen ssm at debian.org
Mon Nov 4 15:02:02 UTC 2013


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit e056b4473df8e7a1ce4039e829f182bd4d217405
Author: Rob Reynolds <ferventcoder at gmail.com>
Date:   Tue Jul 30 10:46:48 2013 -0500

    (#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
---
 lib/facter/util/directory_loader.rb |    2 +-
 lib/facter/util/parser.rb           |   37 +++++++++++++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/lib/facter/util/directory_loader.rb b/lib/facter/util/directory_loader.rb
index 5fc2af1..d0db23d 100644
--- a/lib/facter/util/directory_loader.rb
+++ b/lib/facter/util/directory_loader.rb
@@ -1,7 +1,7 @@
 # A Facter plugin that loads external facts.
 #
 # Default Unix Directories:
-# /etc/facter/facts.d, /etc/puppetlbas/facter/facts.d
+# /etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"
 #
 # Default Windows Direcotires:
 # C:\ProgramData\Puppetlabs\facter\facts.d (2008)
diff --git a/lib/facter/util/parser.rb b/lib/facter/util/parser.rb
index 8f2db60..d03bc4f 100644
--- a/lib/facter/util/parser.rb
+++ b/lib/facter/util/parser.rb
@@ -125,12 +125,45 @@ module Facter::Util::Parser
   end
 
   register(ScriptParser) do |filename|
-    if not Facter::Util::Config.is_windows?
-      File.executable?(filename) && File.file?(filename)
+    if Facter::Util::Config.is_windows?
+      extension_matches?(filename, %w{bat com exe})
+    else
+      File.executable?(filename)
     end
   end
 
+  # Executes and parses the key value output of Powershell scripts
+  #
+  # Before you can run unsigned ps1 scripts it requires a change to execution
+  # policy:
+  #
+  #   Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
+  #   Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
+  #
+  class PowershellParser < Base
+    # Returns a hash of facts from powershell output
+    def results
+      shell_command = "powershell -File #{filename}"
+      output = Facter::Util::Resolution.exec(shell_command)
+
+      result = {}
+      output.split("\n").each do |line|
+        if line =~ /^(.+)=(.+)$/
+          result[$1] = $2
+        end
+      end
 
+      result
+    rescue Exception => e
+      Facter.warn("Failed to handle #{filename} as powershell facts: #{e.class}: #{e}")
+      Facter.debug(e.backtrace.join("\n\t"))
+    end
+  end
+
+  register(PowershellParser) do |filename|
+    Facter::Util::Config.is_windows? && extension_matches?(filename, "ps1")
+  end
+  
   # A parser that is used when there is no other parser that can handle the file
   # The return from results indicates to the caller the file was not parsed correctly.
   class NothingParser

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list