summaryrefslogtreecommitdiff
path: root/fact.rb
blob: 6e66ba6bbce9890e3e189e0a76c23283e3920d6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
# fact.rb
#

module Puppet::Parser::Functions
  newfunction(:fact, :type => :rvalue, :doc => <<-EOS
    EOS
  ) do |arguments|

    raise(Puppet::ParseError, "fact(): Wrong number of arguments " +
      "given (#{arguments.size} for 1)") if arguments.size < 1

    fact = arguments[0]

    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 ...

    #
    # 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 = (result and not result.empty?) ? result : ''

    return result
  end
end

# vim: set ts=2 sw=2 et :