]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Small re-factor of fact function.
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Mon, 25 Apr 2011 22:32:41 +0000 (23:32 +0100)
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Mon, 25 Apr 2011 22:32:41 +0000 (23:32 +0100)
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
fact.rb

diff --git a/fact.rb b/fact.rb
index 806c330bd4816b77d5570d77bf2886b3679a7549..9522293a711c8adb07c1c636fbf758dca57dcd6a 100644 (file)
--- a/fact.rb
+++ b/fact.rb
@@ -4,42 +4,6 @@
 
 module Puppet::Parser::Functions
   newfunction(:fact, :type => :rvalue, :doc => <<-EOS
-This function will retrieve fact from Facter based on the fact
-name and expose it for further use within Puppet manifest file ...
-
-For example:
-
-Given the following sample manifest:
-
-   define partitions {
-     $result = split(fact("partitions_${name}"), ',')
-
-     notice $result
-
-     partition { $result: }
-   }
-
-   define partition {
-     notice $name
-   }
-
-   $available_disks = split($disks, ',')
-
-   partitions { $available_disks: }
-
-This will produce the following:
-
-   notice: Scope(Partitions[hda]): hda1 hda2
-   notice: Scope(Partition[hda1]): hda1
-   notice: Scope(Partition[hda2]): hda2
-
-Which allows you to avoid resorting to the following:
-
-   $fact   = "partitions_${name}"
-   $result = split(inline_template("<%= scope.lookupvar(fact) %>"), ',')
-
-Phasing out the need for use and abuse of the infamous inline_template
-in the partitions define given above.
     EOS
   ) do |arguments|
 
@@ -54,18 +18,20 @@ in the partitions define given above.
     fact   = strinterp(fact) # Evaluate any interpolated variable names ...
     result = lookupvar(fact) # Get the value of interest from Facter ...
 
-    if not result or result.empty?
-      #
-      # Now this is a funny one ...  Puppet does not have a concept of
-      # returning neither undef nor nil back for use within the Puppet DSL
-      # and empty string is as closest to actual undef as you we can get
-      # at this point in time ...
-      #
-      result = ''
-    end
+    #
+    # Now this is a funny one ...  Puppet does not have a concept of
+    # returning neither undef nor nil back for use within the Puppet DSL
+    # and empty string is as closest to actual undef as you we can get
+    # at this point in time ...
+    #
+    result = (not result or result.empty?) ? '' : result
 
     return result
   end
 end
 
 # vim: set ts=2 sw=2 et :
+
+notice fact('interfaces')
+notice fact('xyz')
+notice fact('')