Ask Your Question
0

using hiera in .conf file

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

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

Thanks!

edit retag flag offensive close merge delete

Comments

Do you mean inside .conf template?

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

Yes that is correct.

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

1 Answer

Sort by » oldest newest most voted
0

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

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

 # 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 ( 
      $device_id, 
  ) {
     file { '/var/config/settings.json': 
        content => template('media/var/config/settings.json.erb'),
        ensure  => 'file',
    }
  }

Template

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

Comments

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 -0500 )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 -0500 )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

Stats

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

Seen: 41 times

Last updated: Aug 16 '16