Hiera Interpolation

484 views
Skip to first unread message

Matthew Ceroni

unread,
Nov 30, 2015, 6:43:25 PM11/30/15
to puppet...@googlegroups.com
I have been using variable interpolation within my Hiera data files for sometime.

For instance I have Citrix NetScaler LB rules defined as such:

apache:
      name: "%{::cluster}-apache"
      ensure: 'present'
      service_type: 'HTTP'
      state: true
      lb_method: 'LEASTCONNECTION'

And based on the cluster the machine is in (cluster is a parameter set by my ENC) it creates the rule accordingly.

However I know have a need to interpolate variables that might be be arrays or hashes. Is there a way I can interpolate a hash key, value within a hiera data file from a variable in the current scope?

I know within hiera I can reference other keys using hash and look-up based on a key, but this data isn't another key within the data file, it is a variable set by my ENC available in the current scope (just like cluster was). 

Thanks

Matthew Ceroni

unread,
Dec 1, 2015, 1:06:33 PM12/1/15
to Puppet Users
So it appears you can interpolate array and hash variables (https://docs.puppetlabs.com/hiera/2.0/variables.html#interpolating-hash-or-array-elements)

I am currently running Puppet Master 3.8 (can't upgrade to 4 as of this moment as I integrate with Foreman).

Puppet 3.8 packages come with Hiera 1.3.5 and to use the above you need 2.0 or higher. Therefore I removed the hiera 1.3.5 RPM (just broke the dependency on Puppet master 3.8) and installed 3.0.5 hiera gem. However I am receiving the following error when attempting to interpolate a key within a hash following the above documentation:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Empty string title at 0. Title strings must have a length greater than zero. at /etc/puppet/environments/sandbox/manifests/site.pp:25:11

My thought is that even though I removed Hiera 1.3.5 that it didn't fully get removed and Puppet master is still using it. The reason for this is with Hiera 2.0 and up the default location for hiera.yaml is now /etc/puppetlabs/code/hiera.yaml. I haven't created that file and just left /etc/puppet/hiera.yaml. If I remove /etc/puppet/hiera.yaml I get the standard error that hiera couldn't find the key in any lookup-files. Therefore it doesn't appear to be using /etc/puppetlabs/code/hiera.yaml.

Is there a way to verify what version of Hiera puppet is using and force it to use a specific version? 
Reply all
Reply to author
Forward
0 new messages