Ask Your Question

Can you use automatic parameter lookup with defined types?

asked 2014-12-18 21:15:31 -0500

rnelson0 gravatar image

Automatic Parameter Lookup ( ) allows me to have class parameters that are overridden by hiera values. Can anything similar be done with hiera? For example, when using apache::vhost, it's fairly common for me to start with:

apache::vhost{ 'site':
  port => 443,

Setting $apache::vhost::port has no effect. Other than creating another defined type that wraps around apache::vhost, how can I set the default without peppering classes with Apache::Vhost{ port => 443 }?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2014-12-19 02:46:08 -0500

Cardil gravatar image

I would do just:

Apache::Vhost {
  port => hiera('apache::vhost::port, 443)
edit flag offensive delete link more


That works, but like I said I didn't want to have to pepper it throughout. It just seems like APL should apply to defined types as well as classes, even if that's clearly not the way it actually works :)

rnelson0 gravatar imagernelson0 ( 2014-12-19 09:37:14 -0500 )edit

APL should be renamed to Automatic Class Parameter Lookup. As cbarbour states, there is no way to do this with defined or native types. APL has no idea which instance of the type to which the value applies.

razorsedge gravatar imagerazorsedge ( 2014-12-20 12:56:21 -0500 )edit

answered 2014-12-19 15:32:12 -0500

cbarbour gravatar image

Automatic parameter lookups are not supported with Defined types or with native types. Cardil's solution is best practice, at the moment.

edit flag offensive delete link more

answered 2014-12-19 11:40:11 -0500

Tomasz Olszewski gravatar image

updated 2014-12-19 11:40:48 -0500

Hi melson0

In such case I prefer to create hash array in hiera, and then pass it to create_resources function ( )

Here you'll find a lot of informations:

edit flag offensive delete link more


I'll still have to define 'port: 443' for every apache::vhost in the hash, though, right? I can't define one key to be used in all sub-keys that I am aware of.

rnelson0 gravatar imagernelson0 ( 2014-12-19 15:34:47 -0500 )edit

If you're using the "usual" pattern with a common.yaml or global.yaml file, hiera_hash will merge what it finds in all levels. Put the port 443 specification in a global/common level of the hierarchy, and specifics at node level.

fnaard gravatar imagefnaard ( 2015-01-02 13:08:18 -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


Asked: 2014-12-18 21:15:31 -0500

Seen: 438 times

Last updated: Dec 19 '14