Ask Your Question
0

Can you use automatic parameter lookup with defined types?

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

rnelson0 gravatar image

Automatic Parameter Lookup ( https://docs.puppetlabs.com/hiera/1/p... ) 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
2

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

Cardil gravatar image

I would do just:

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

Comments

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

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

Tomasz Olszewski gravatar image

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

Hi melson0

In such case I prefer to create hash array in hiera, and then pass it to create_resources function ( https://docs.puppetlabs.com/reference... )

Here you'll find a lot of informations: https://ask.puppetlabs.com/question/2077/how-are-people-using-hiera-with-defined-types/

edit flag offensive delete link more

Comments

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 -0600 )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. https://docs.puppetlabs.com/hiera/1/lookup_types.html#hash-merge

fnaard gravatar imagefnaard ( 2015-01-02 13:08:18 -0600 )edit
0

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

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

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: 2014-12-18 21:15:31 -0600

Seen: 627 times

Last updated: Dec 19 '14