Ask Your Question

How are people using Hiera with Defined Types?

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

Ancillas gravatar image

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

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

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

ramindk gravatar image

I use it with create_resources. Did a write up of it here,

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


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

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

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

cosman2001 gravatar image

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

ramindk gravatar image

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

define nginx::vhost(
   $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


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 -0600 )edit

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 -0600 )edit

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

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

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

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:

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


404 not found on github repo you posted.

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



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

Seen: 11,450 times

Last updated: Sep 21 '14