Ask Your Question

Hiera calling a parameter set in a module

asked 2016-03-01 20:34:22 -0500

ulankford gravatar image

updated 2016-03-04 00:27:27 -0500

I am wondering if it is possible or if there is a better way for having a yaml file used by Hiera to have dymanic configuration

My current hiera config is as follows.

  - yaml

  - "node/%{::clientcert}"
  - "role/%{::dec_role}"
  - "dc/%{::dec_dc}"
  - common
  - firewall

For a role, I want to create an autofs resource however, I also want to pass in a specific parameter. Yaml file for role is as follows.

        mount: /-
        mapfile: /etc/autofs.d/
        mapcontents: '/srv/ice -fstype=cifs,noperm,credentials=/etc/autofs.d/cred/ice_flat_files %{::ice::params::ice_server}/ICE_Flat_Files'
        options: --timeout=600
        order: 4

Note that I have tired to pass in a parameter I already have set in ice::params::ice_server

However, nothing gets passed in, so it means this is a null value I assume at the moment. So my question is, can one pass a parameter into Hiera like you would with a normal class or module or can Hiera call this type of parameter.

I could create node yaml file and have this set statically but would prefer to have the one role yaml file and have this working dynamically for all my servers.

Hope I am clear and thanks.

EDIT: To add....

The parameter ice::params::ice_server can be found in a module I have written. Note $env is a fact we have to determine the environment.

class ice::params::ice_server {
  if $env == 'tst' {
     $ice_server = 'testserver03'
  elsif $env == 'prd' {
     $ice_server = 'prodserver04'

Setting the parameter is not an issue and calling itin side other modules is OK, I have done that many times before, but calling it in Heira is not something I have done before.

Looking at the puppet documentation the syntax is supposed to be %{::ice::params::ice_server} however in my yaml file this doesn't return anything. I'm thinking do I need to inherit it somehow or perhaps the scope is wrong?

Hope this makes it clearer.

edit retag flag offensive close merge delete


You'll need to be clearer. I don't know which parameter you're referring to; you refer to ice::params::ice_server ; we can't see your actual code etc

Alex Harvey gravatar imageAlex Harvey ( 2016-03-03 00:28:44 -0500 )edit

I think I know what you're trying to do. Give me a bit.

Alex Harvey gravatar imageAlex Harvey ( 2016-03-04 01:39:59 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-03-04 01:54:23 -0500

To begin with, you have misunderstood the purpose of Params classes.

Params is a special class where we, by convention, set world-wide default value in our modules. These should be defaults that make sense independently of your site. An example would be the default locations of NTP configuration files on Red Hat Linux and Solaris. The location /etc/ntp.conf is true everywhere. What you have in Params, however, is site-specific data, and it belongs in Hiera, not in Params. It's the hostname for your ice server.

To answer your specific question, you could use the scope function, however you should refactor so that your defaults are in Hiera to begin with. After you refactor, you may find other information about how to look up Hiera values within Hiera itself useful, and this information is on the same page I linked.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2016-03-01 20:34:22 -0500

Seen: 83 times

Last updated: Mar 04 '16