source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/pick_default.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 8 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

File size: 1.2 KB
Line 
1module Puppet::Parser::Functions
2 newfunction(:pick_default, :type => :rvalue, :doc => <<-EOS
3
4This function is similar to a coalesce function in SQL in that it will return
5the first value in a list of values that is not undefined or an empty string
6(two things in Puppet that will return a boolean false value). If no value is
7found, it will return the last argument.
8
9Typically, this function is used to check for a value in the Puppet
10Dashboard/Enterprise Console, and failover to a default value like the
11following:
12
13 $real_jenkins_version = pick_default($::jenkins_version, '1.449')
14
15The value of $real_jenkins_version will first look for a top-scope variable
16called 'jenkins_version' (note that parameters set in the Puppet Dashboard/
17Enterprise Console are brought into Puppet as top-scope variables), and,
18failing that, will use a default value of 1.449.
19
20Note that, contrary to the pick() function, the pick_default does not fail if
21all arguments are empty. This allows pick_default to use an empty value as
22default.
23
24EOS
25) do |args|
26 fail "Must receive at least one argument." if args.empty?
27 default = args.last
28 args = args[0..-2].compact
29 args.delete(:undef)
30 args.delete(:undefined)
31 args.delete("")
32 args << default
33 return args[0]
34 end
35end
Note: See TracBrowser for help on using the repository browser.