You will most likely find yourself in need of some data from Hiera when designing templates for configuration or other files. For example, when building your personal module in order to manage the SSH server, you might want to allow nodes to specify a list of environment variables for the AcceptEnv
option.
Tip
Granted, this will most likely be passed as a parameter to a class within such a module. The Hiera data will just be bound to the parameter and be available to the template as a regular Puppet variable. Let's ignore this just to have a contrived example for data retrieval from a template.
The naïve implementation would not work inside the template:
<% # pseudo code! vars = hiera('ssh::server::env_vars', [ 'LANG', 'LC_*' ]) -%> AcceptEnv = <%= vars * ' ' %>
The issue is that this call will be directed at a hiera
method in Ruby and not the Puppet function. Templates have a way of accessing Puppet's parser functions, but it takes just a little...