Puppet Function: puppetdb_lookup_key
- Defined in:
- vendor_modules/puppetdbquery/lib/puppet/functions/puppetdb_lookup_key.rb
- Function type:
- Ruby 4.x API
Overview
The `puppetdb_lookup_key` is a hiera 5 `lookup_key` data provider function. See (docs.puppet.com/puppet/latest/hiera_custom_lookup_key.html) for more info.
See README.md#hiera-backend for usage.
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 34 |
# File 'vendor_modules/puppetdbquery/lib/puppet/functions/puppetdb_lookup_key.rb', line 7 Puppet::Functions.create_function(:puppetdb_lookup_key) do dispatch :puppetdb_lookup_key do param 'String[1]', :key param 'Hash[String[1],Any]', :options param 'Puppet::LookupContext', :context end def puppetdb_lookup_key(key, , context) return context.cached_value(key) if context.cache_has_key(key) if !key.end_with?('::_nodequery') && nodequery = call_function('lookup', "#{key}::_nodequery", 'merge' => 'first', 'default_value' => nil) # Support specifying the query in a few different ways query, fact, sort = case nodequery when Hash then [nodequery['query'], nodequery['fact'], nodequery['sort']] when Array then nodequery else [nodequery.to_s, nil, nil] end paramz = [query, fact].compact result = call_function('query_nodes', *paramz) result.sort! if sort context.cache(key, result) else context.not_found end end end |