Ask Your Question
5

How are people using Hiera with Defined Types?

asked 2013-07-16 16:53:57 -0500

Ancillas gravatar image

updated 2013-07-16 16:54:50 -0500

What's the best way to use Hiera and Defined Types together?

Puppet data bindings work great for classes, but I use some defined types for managing resources such as apt sources with Apt::Source (via puppetlabs/apt).

Are folks using hiera_hash() in combination with create_resources, or is there a better way?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
5

answered 2013-07-16 17:38:46 -0500

ramindk gravatar image

I use it with create_resources. Did a write up of it here, https://ask.puppetlabs.com/question/1655/an-end-to-end-roleprofile-example-using-hiera/

Overall I like the idea of installing and configing daemons with modules and using defines, hiera, create_resources, and some sort of wrapper class to add functionality to it. Makes a lot more sense than some of these parametrized kitchen sink modules I've been seeing lately.

edit flag offensive delete link more

Comments

Looks like a pretty good approach to me. Thanks :).

Ancillas gravatar imageAncillas ( 2013-07-18 23:47:29 -0500 )edit
3

answered 2014-07-03 03:06:29 -0500

cosman2001 gravatar image

updated 2014-07-03 15:21:04 -0500

ramindk gravatar image

I use hiera with defined types very similar to how folks were using hiera before puppet 3.

define nginx::vhost(
   $port,
   $enable_auto_index = hiera('nginx::enable_auto_index', 'false')
){
}

You can use whatever lookup key you like but I try and stick to the stander lookup key formula that puppet generates when using hiera with classes (nginx::vhost::enable_auto_index).

Additionally, you can also specify a default value (2nd parameter). If you don't specify this default then you would get compile errors during hiera lookups, which offers a similar protection to required parameters.

edit flag offensive delete link more

Comments

As of Puppet 3.x you don't need the hiera() lookup stuff. It will automatically lookup everything hiera.

baurmatt gravatar imagebaurmatt ( 2014-08-21 06:38:47 -0500 )edit
2

But the automatic lookup works only for classes, not (defined) types, as there can be multiple instances. The problem with this approach is that the hiera() call must be in the code, so it works only for stuff you write yourself.

rmaeder gravatar imagermaeder ( 2014-08-28 02:59:18 -0500 )edit
1

answered 2014-08-28 03:04:33 -0500

rmaeder gravatar image

To declare defaults of a defined type with hiera lookup you can use

Nginx::Vhost {
  enable_auto_index => hiera('nginx::vhost::enable_auto_index', 'false'),
}

and then all your defined vhosts in the scope of this declaration will use this default.

edit flag offensive delete link more
0

answered 2014-09-21 01:40:35 -0500

I built a hiera_manifest functionality at my job. Essentially it allows you to call modules, classes and parameters and defined types all via hiera yaml.

I just put it up on Github to share: https://github.com/mlbam/hiera_manifest

This has slight advantages in that parameters are also put in place at the time of invocation of the module, class or type.

One thing to note is the difference in some syntax for resource definitions when using metaparameters. Also, when troubleshooting, the errors stick to the manifest sometimes and you don't get a proper error message for the module that throws the error.

edit flag offensive delete link more

Comments

404 not found on github repo you posted.

felipe1982 gravatar imagefelipe1982 ( 2016-01-26 18:15:19 -0500 )edit
elmobp gravatar imageelmobp ( 2016-09-12 04:51:59 -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

3 followers

Stats

Asked: 2013-07-16 16:53:57 -0500

Seen: 9,762 times

Last updated: Sep 21 '14