How do I get this hiera hash lookup to work properly?

asked 2015-05-28 23:37:17 -0600

patrick gravatar image

updated 2015-06-01 09:02:37 -0600

I am using a Hiera hash to hold some token values which are host-specific. the keys within the hash correspond to the hostname/certname of the node(s) that'll be classified with the profile module that calls the hash value. However, when I apply the module, the value which corresponds to the hash key for the host is always null. Here's the code I'm working with.

in hiera-file.yaml

  host-name1: 'abcdef123'
  host-name2: 'abbcde456'

and in profile.pp

$_tokens = hiera_hash('token_lookup', undef, 'hiera-file')
$_specific_token = $_tokens["${::hostname}"]       <== never gets a value

I'm certain that the hostname matches the key in the hash. The question is, what's the right syntax here for getting the value from the hiera-file to populate properly? Thank you in advance for the advice.

edit: I think I've narrowed the issue to the notion that the hostnames have dashes/hyphens in them. Quoting the keys doesn't seem to provide the same benefit that quoting a value does for escape-needed characters. I didn't think the literal dash mattered, and it passes YAML lint/syntax checks, but even in canonical YAML format I can't get the lookup to match the hostname. Looking now more specifically for advice on escaping characters in the key

edit retag flag offensive close merge delete


Hmm, seems to work fine here. I assume you've added notify{} or notice() to your code to check the values of $_tokens and $::hostname to make sure the right data is returned and indexed into?

GregLarkin gravatar imageGregLarkin ( 2015-05-31 22:26:27 -0600 )edit

Thanks for the comment; yes I'm using a notify to check values. I updated the question with some potential discovery that having dashes in the key name seems to be the problem.

patrick gravatar imagepatrick ( 2015-06-01 09:03:34 -0600 )edit