summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-25 23:32:41 +0100
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-25 23:32:41 +0100
commit50cb2cd05afb44b02eda90be95139c01903f4090 (patch)
tree267b050ff029d0b8dd922266af0bd5afbdade154
parent7e7c7ce2ee176017620987c36e4dd5abc2dd304b (diff)
downloadpuppet-stdlib-50cb2cd05afb44b02eda90be95139c01903f4090.tar.gz
puppet-stdlib-50cb2cd05afb44b02eda90be95139c01903f4090.tar.bz2
Small re-factor of fact function.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r--fact.rb56
1 files changed, 11 insertions, 45 deletions
diff --git a/fact.rb b/fact.rb
index 806c330..9522293 100644
--- 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('')