On 2019-02-27 00:01, comport3 wrote:
Hi Henrik and Group,

Thank you very much, this sounds like exactly what we are after. After reviewing https://puppet.com/docs/puppet/6.3/hiera_custom_backends.html we are a little lost as to how to get started. Does anyone have any example code of using a Customer Backend or Puppet Function in conjunction with a Deferred data type lookup for us to review? Anything including the Vault lookup logic or some 'proof of concept' code would be a much welcomed starting point.


It is actually dead simple - here is an example that returns a hard coded deferred. The example is written in the Puppet Language, and is autoloaded just like other functions from "mymodule".

This simple example is a "data hash" kind of backend - it is called once
and is expected to return a hash with key => value bindings.

  function mymodule::deferred_example(
    Hash                  $options,
    Puppet::LookupContext $context,
  ) {
    # Return a hash with key(s) bound to Deferred value(s)
    { 'the_key' => Deferred('vault_lookup', ['the key']) }
  }

Then there are lots of different things you could do.

The $options hash contains information from hiera.yaml:
- if a path/URI was given or not (and that path existed)
- any custom options given in hiera.yaml for this entry

This means you could configure what the backend would do based on either
options given directly (a list of keys for which this backend should return a Deferred), or you can use the path to read such data from a file, using say a function to read that file as json from the path in options.

To use this backend simply enter its name in hiera.yaml like you do for other backend functions.

Another alternative is to write a backend of "lookup key" kind. The contract there is to return a value per key or that the $context.not_found() is called (if it does not have a value for the key).

If you go this route, then the function could for example lookup a key in hiera that holds the names of keys to lookup in a deferred way. Or, if you design it so that all deferred parameters can be identified via their name then you could simply return a Deferred for all keys that match a pattern.

Read all the details starting from here: https://puppet.com/docs/puppet/latest/hiera_custom_backends.html

Hope this helps.
- henrik


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/q55ofs%245ttr%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to