diff --git a/lib/puppet/parser/functions/hiera.rb b/lib/puppet/parser/functions/hiera.rb index 93d09d425..c57c94e28 100644 --- a/lib/puppet/parser/functions/hiera.rb +++ b/lib/puppet/parser/functions/hiera.rb @@ -1,34 +1,35 @@ require 'hiera_puppet' module Puppet::Parser::Functions newfunction(:hiera, :type => :rvalue, :arity => -2, :doc => "Performs a standard priority lookup and returns the most specific value for a given key. The returned value can be data of any type (strings, arrays, or hashes) The function can be called in one of three ways: 1. Using 1 to 3 arguments where the arguments are: 'key' [String] Required The key to lookup. 'default` [Any] Optional A value to return when there's no match for `key`. Optional `override` [Any] Optional An argument in the third position, providing a data source to consult for matching values, even if it would not ordinarily be part of the matched hierarchy. If Hiera doesn't find a matching key in the named override data source, it will continue to search through the rest of the hierarchy. 2. Using a 'key' and an optional 'override' parameter like in #1 but with a block to provide the default value. The block is called with one parameter (the key) and - should return the value. This option can only be used with the 4x version of the function. + should return the value. This option can only be used with the 3x future parser or + from 4.0.0. 3. Like #1 but with all arguments passed in an array. More thorough examples of `hiera` are available at: ") do |*args| key, default, override = HieraPuppet.parse_args(args) HieraPuppet.lookup(key, default, self, override, :priority) end end diff --git a/lib/puppet/parser/functions/hiera_array.rb b/lib/puppet/parser/functions/hiera_array.rb index 3798a8bfa..b4ca2872f 100644 --- a/lib/puppet/parser/functions/hiera_array.rb +++ b/lib/puppet/parser/functions/hiera_array.rb @@ -1,36 +1,37 @@ require 'hiera_puppet' module Puppet::Parser::Functions newfunction(:hiera_array, :type => :rvalue, :arity => -2,:doc => "Returns all matches throughout the hierarchy --- not just the first match --- as a flattened array of unique values. If any of the matched values are arrays, they're flattened and included in the results. The function can be called in one of three ways: 1. Using 1 to 3 arguments where the arguments are: 'key' [String] Required The key to lookup. 'default` [Any] Optional A value to return when there's no match for `key`. Optional `override` [Any] Optional An argument in the third position, providing a data source to consult for matching values, even if it would not ordinarily be part of the matched hierarchy. If Hiera doesn't find a matching key in the named override data source, it will continue to search through the rest of the hierarchy. 2. Using a 'key' and an optional 'override' parameter like in #1 but with a block to provide the default value. The block is called with one parameter (the key) and - should return the value. This option can only be used with the 4x version of the function. + should return the value. This option can only be used with the 3x future parser or + from 4.0.0. 3. Like #1 but with all arguments passed in an array. If any matched value is a hash, puppet will raise a type mismatch error. More thorough examples of `hiera` are available at: ") do |*args| key, default, override = HieraPuppet.parse_args(args) HieraPuppet.lookup(key, default, self, override, :array) end end diff --git a/lib/puppet/parser/functions/hiera_hash.rb b/lib/puppet/parser/functions/hiera_hash.rb index 6656bfd07..01369de8a 100644 --- a/lib/puppet/parser/functions/hiera_hash.rb +++ b/lib/puppet/parser/functions/hiera_hash.rb @@ -1,38 +1,39 @@ require 'hiera_puppet' module Puppet::Parser::Functions newfunction(:hiera_hash, :type => :rvalue, :arity => -2, :doc => "Returns a merged hash of matches from throughout the hierarchy. In cases where two or more hashes share keys, the hierarchy order determines which key/value pair will be used in the returned hash, with the pair in the highest priority data source winning. The function can be called in one of three ways: 1. Using 1 to 3 arguments where the arguments are: 'key' [String] Required The key to lookup. 'default` [Any] Optional A value to return when there's no match for `key`. Optional `override` [Any] Optional An argument in the third position, providing a data source to consult for matching values, even if it would not ordinarily be part of the matched hierarchy. If Hiera doesn't find a matching key in the named override data source, it will continue to search through the rest of the hierarchy. 2. Using a 'key' and an optional 'override' parameter like in #1 but with a block to provide the default value. The block is called with one parameter (the key) and - should return the value. This option can only be used with the 4x version of the function. + should return the value. This option can only be used with the 3x future parser or + from 4.0.0. 3. Like #1 but with all arguments passed in an array. `hiera_hash` expects that all values returned will be hashes. If any of the values found in the data sources are strings or arrays, puppet will raise a type mismatch error. More thorough examples of `hiera_hash` are available at: ") do |*args| key, default, override = HieraPuppet.parse_args(args) HieraPuppet.lookup(key, default, self, override, :hash) end end diff --git a/lib/puppet/parser/functions/hiera_include.rb b/lib/puppet/parser/functions/hiera_include.rb index 099049f19..9c9c9536e 100644 --- a/lib/puppet/parser/functions/hiera_include.rb +++ b/lib/puppet/parser/functions/hiera_include.rb @@ -1,54 +1,55 @@ require 'hiera_puppet' module Puppet::Parser::Functions newfunction(:hiera_include, :arity => -2, :doc => "Assigns classes to a node using an array merge lookup that retrieves the value for a user-specified key from a Hiera data source. To use `hiera_include`, the following configuration is required: - A key name to use for classes, e.g. `classes`. - A line in the puppet `sites.pp` file (e.g. `/etc/puppet/manifests/sites.pp`) reading `hiera_include('classes')`. Note that this line must be outside any node definition and below any top-scope variables in use for Hiera lookups. - Class keys in the appropriate data sources. In a data source keyed to a node's role, one might have: --- classes: - apache - apache::passenger The function can be called in one of three ways: 1. Using 1 to 3 arguments where the arguments are: 'key' [String] Required The key to lookup. 'default` [Any] Optional A value to return when there's no match for `key`. Optional `override` [Any] Optional An argument in the third position, providing a data source to consult for matching values, even if it would not ordinarily be part of the matched hierarchy. If Hiera doesn't find a matching key in the named override data source, it will continue to search through the rest of the hierarchy. 2. Using a 'key' and an optional 'override' parameter like in #1 but with a block to provide the default value. The block is called with one parameter (the key) and should return the array to be used in the subsequent call to include. - This option can only be used with the 4x version of the function. + This option can only be used with the 3x future parser or + from 4.0.0. 3. Like #1 but with all arguments passed in an array. More thorough examples of `hiera_include` are available at: ") do |*args| key, default, override = HieraPuppet.parse_args(args) if answer = HieraPuppet.lookup(key, default, self, override, :array) method = Puppet::Parser::Functions.function(:include) send(method, [answer]) else raise Puppet::ParseError, "Could not find data item #{key}" end end end