summaryrefslogtreecommitdiff
path: root/fact.rb
diff options
context:
space:
mode:
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-25 02:02:00 +0100
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-25 02:02:00 +0100
commit61936fdeaaadb25e83ccb766e6b9ac872527a50d (patch)
treedac755376a7fcf23ffb4c834a400de36fd938eb7 /fact.rb
parent4a72b0efde7069f76b142cc2349f4ec60001a50d (diff)
Updated error check and reporting. Also we now return empty
string value i.e. "" instead of raising an exception when a particular fact is not present. We also make use of strinterp() explicitly to evaluate arguments passed to the function. Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Diffstat (limited to 'fact.rb')
-rw-r--r--fact.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/fact.rb b/fact.rb
index 95213cc..2c22f60 100644
--- a/fact.rb
+++ b/fact.rb
@@ -44,17 +44,25 @@ partitions define given above.
EOS
) do |arguments|
- raise(Puppet::ParseError, "Wrong number of arguments " +
+ raise(Puppet::ParseError, "fact(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
fact = arguments[0]
- raise(Puppet::ParseError, 'You must provide fact name') if fact.empty?
+ raise(Puppet::ParseError, 'fact(): You must provide ' +
+ 'fact name') if fact.empty?
+ fact = strinterp(fact) # Evaluate any interpolated variable names ...
result = lookupvar(fact) # Get the value of interest from Facter ...
if not result or result.empty?
- raise(Puppet::ParseError, "Unable to retrieve fact `#{fact}'")
+ #
+ # 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
return result