Ask Your Question
2

Refactoring Puppet Modules to Remove the Hiera Coupling

asked 2016-08-11 01:57:50 -0500

izza gravatar image

updated 2016-08-11 04:53:44 -0500

Hi all,

For a set of Puppet modules which are tightly coupled to hiera, I'm trying to figure out a way to decouple from hiera and provide a suitable way to supply a set of default parameters. A sample class (non-refactored) is shown at [1].

One possible option I though of using is the params class model, which uses a params class to include the default mandatory parameters. By default, the hiera lookups can be commented out so that the default parameters in params class is picked. I referred the ntp puppet module as a reference [2].

wdyt of this method? What would be a cleaner approach?

Thank you!

[1].

  class foo inherits base {
        $foo1       = hiera('foo1param')
        $foo2       = hiera('foo2param')

        # other logic
 }

[2]. https://github.com/puppetlabs/puppetl...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-08-11 20:04:17 -0500

kaizenCoder gravatar image

I don't know if you employee the roles and profiles pattern but if you did, that'd be where you would do your heira lookups (if needed ofcourse). Otherwise you're on the right path of using the params pattern to store your application specific defaults. This is an important distinction because hiera is for site specific data, meaning something specific to your environment/site where as the application or module defaults should be sane defaults to get it up and running in any site/environment.

From an ordering point of view it goes like this:

  1. Class resource like declaration. This is explicit parameter passing.
  2. Puppet automatically looks up parameters in Hiera
  3. Defaults

https://docs.puppet.com/hiera/3.2/pup...

I personally do not use automatic data binding (2) due to the debugging nightmare you can run into. I explicitly pass params where I do the hiera lookups (inside my profile) or use defaults via params.

To wrap up, it is a good idea to remove the coupling to hiera for the aforementioned reasons and provide sane defaults like you plan to do. If hiera look ups are required pass them as class params with a look up.

Hope this gives you some clarity.

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

1 follower

Stats

Asked: 2016-08-11 01:57:50 -0500

Seen: 103 times

Last updated: Aug 11 '16