puppethiera

Puppet lookup() with period inside Hiera variable name


I'm looping a list of users from Hiera like:

users 
 - bob.joe
 - jill.dill

and using the lookup() function to find their pub key I have stored in Hiera like:

sshkey::bob.joe: 'ssh-rsa ...'
sshkey::jill.dill: 'ssh-rsa ...'

Is it possible to escape the period or format the lookup() function so it doesn't interpret the last name as a subkey? I could strip the period (e.g. "bob.joe" -> "bobjoe") but that's not ideal

Code Example

$users.each |$user| {
 accounts::user { "$user":
  sshkeys => [ 
   lookup("sshkey::${user}")
  ]
 }
}

Solution

  • Finally found the solution at the very bottom of the Puppet docs for "Looking up with Hiera"

    Note: Using extra quotes prevents digging into dotted keys. For example, if the lookup key contains a dot (.) then the entire key must be enclosed within single quotes within double quotes, for example,lookup("'has.dot'").

    Source: https://www.puppet.com/docs/puppet/8/hiera_automatic.html#hiera_dotted_notation

    Now I have it working:

    lookup("'sshkey::${user}'")