Ask Your Question

using hiera in .conf file

asked 2016-08-15 14:40:10 -0600

Please provide examples on how to use hiera lookups inside a .conf file, should that be possible and allowed.


edit retag flag offensive close merge delete


Do you mean inside .conf template?

kaizenCoder gravatar imagekaizenCoder ( 2016-08-15 20:13:21 -0600 )edit

Yes that is correct.

Redsmile gravatar imageRedsmile ( 2016-08-16 09:30:28 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2016-08-16 18:56:31 -0600

kaizenCoder gravatar image

Performing a direct lookup inside the template is discouraged. See here.

In general, don’t use the Hiera functions from templates. That pattern is too obscure, and will hurt your code’s maintainability..

However, you can do this like so:

# Assign to variable
<% device_id = scope.function_hiera(['media::device_id']) -%>

# Display
<%= scope.function_hiera(['media::device_id']) %>

A Better way

The following example illustrates how you create an interface to define the flow of data. You will also notice how the variable is in a local scope.


 # manifests/init.pp
  class media(
      $device_id = hiera('media::device_id')

     class { 'media::install': }
     class {'media::config': 
       device_id => $device_id,

  # manifest/config.pp
  class media::config ( 
  ) {
     file { '/var/config/settings.json': 
        content => template('media/var/config/settings.json.erb'),
        ensure  => 'file',


<%=  @device_id -%>
edit flag offensive delete link more


Please let me know if it solves the problem as looking for a parameter from hiera in file1.conf which is the configuration file setup in the puppet master?

Redsmile gravatar imageRedsmile ( 2016-08-17 09:13:25 -0600 )edit

My understanding is that if we have a class, it would be in a module that agent invokes during it's run.

Redsmile gravatar imageRedsmile ( 2016-08-17 09:14:02 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-08-15 14:40:10 -0600

Seen: 88 times

Last updated: Aug 16 '16