Ask Your Question
0

Is it possible to eval (compute) class parameters from ENC ?

asked 2016-10-24 03:15:31 -0600

Sylvain gravatar image

Let's say I have a parameter with a default value, like

class example (
    $param = $name ? {/foo/ => "foo", default => "bar"},
)

If I don't override this parameter in my ENC (in my case, in foreman), everything happens as expected : the "$param" value depends on the value of "$name", and is either "foo" or "bar".

But if the value is overrided in the ENC with the same kind of thing, it seems that it's not interpreted (evaluated); for example, if I set it to "$name"; my ENC is :

---
classes:
  example:
    param: $name
    [...]

(Note that the value is not quoted) and when I print the value of "param" in a file, it puts "$name" (not the value of name, just "$name", as in the ENC, without quotes).

I understand why the devs wanted this to not work; most of the time, if we override something, it is to set a constant. But in my case, it will be verty handy if it was possible to force the computation of the value from ENC, just like with default value.

PS: I would be interested even if I have to modify puppet code a little bit;

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-10-24 14:34:55 -0600

lavaman gravatar image

Putting a selector in the class declaration is bad style. You should default to undef and set a local variable to the value returned by the selector if param is set to undef, otherwise set the local variable to the value of param and use the local variable everwhere in your puppet class and templates.

edit flag offensive delete link more

Comments

I can't do that, for several reasons: 1) other admins will see in foreman "undef" as default value and will think that they HAVE to override it; or at least they won't know what it will be replaced by; 2) what I want may be "bad style", but it's what I need; it eases stuff a lot in MY use case

Sylvain gravatar imageSylvain ( 2016-10-25 03:20:41 -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

1 follower

Stats

Asked: 2016-10-24 03:02:12 -0600

Seen: 60 times

Last updated: Oct 24 '16