accessing hiera-hash with subkey using a fact

asked 2017-07-24 02:55:54 -0600

sluetze gravatar image


Using opensource puppet 4.10 im trying to access the subkey of a hiera-hash in my puppetmodule using the subkey method. I have to access the subkey depending on a customfact (customenvironment, which is a identifier for a domain-forrest). The goal is to have the correct username for a list of admins depending on the environment while only writing them down once (in hiera-data).

init.pp (takes a hash called $admins, defaults to a hiera-hash)

  $admins.each |String $key, Hash $value| {

    $username = $value.$::customenvironment 

puppet parser validate throws a Syntaxerror at the subkey.

furthermore i have an hiera-hash in hiera which looks like that


        env1: env1username1
        env2: env2username1
        env3: env3username1
        env1: env1username2
        env2: env2username2
        env3: env3username2

env1, env2 ... are the values my customenvironment shows. in the end i want to access the correct username in each "environment" for the admin. there is no possibility to do this through "casing" and substitution of strings, since the names usernames have nothing in common.

Any idea how i can access the subkey dependend on the fact?

i would like to avoid stuff like this:

if ($customenvironment == 'env1') {
  $c_env = $value.env1
elsif ($custonenvironment == 'env2') {
  $c_env = $value.env2
edit retag flag offensive close merge delete