Override optional puppet class parameters

I have a class with an optional parameter

class example (
  Optional[String] $example = undef,
) { ... }

If I override this in foreman, it sets the default behavior parameter type to string and the default value to undef which makes this the string "undef" and not the undef.

So how can I override an optional parameter without setting some default value?

Running Foreman 3.9.3 on Alma 8.4.

You can use the “omit” option for the smartclass parameter in Foreman.
That option means “This parameter can be overridden, but only send it if there is an override value set for this host”.
I think this should solve your problem? Otherwise, I might be misunderstanding what you are trying to achieve.

1 Like

Thanks, I have only read the description for the omit checkbox

Omit parameter from classification
Foreman will not send this parameter in classification output.

and that sounds very different from what you wrote. I thought, it would never send the parameter if I set it. I’ll have to test.

Yes, the description is rather vague, but we use that option extensively and it works just as I described.

1 Like

You are right. It does. The explanation in the tooltip could really be clearer. If you see it in the context and think about what it might do at that place, I guess, it makes sense, but so far I have never spend too much time on that and just read what it says and thought it would leave it out completely (which doesn’t really make much sense now that I think about it)…

$ grep -rni 'Foreman will not send this parameter in classification output.' --exclude-dir={locale,node_modules}
app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb:49:          param :omit, :bool, desc: N_('Foreman will not send this parameter in classification output.'\
app/controllers/foreman_puppet/api/v2/override_values_controller.rb:39:            param :omit, :bool, required: false, desc: N_('Foreman will not send this parameter in classification output')

Feel free to come up with a better explanation and open a PR. We are happy to improve the plugin!


Just saw that it is not as easy as that. The message that is rendered is actually hidden in Foreman core: foreman/app/helpers/common_parameters_helper.rb at develop · theforeman/foreman · GitHub

(not sure where the message might be used except in foreman_puppet, but if the usage is the same, the message still can be improved I guess)

Right now, understanding what it does and how to interpret the current texts in the context (as simple user of puppet and no expert fluent with the puppet terminology) I think the first misleading thing about the page editing the class parameters is the placement of the override checkbox. Currently it’s in the “Default Behavior” section:

Default Behavior

Override the default value of the Puppet class parameter.

Override x

Now the override isn’t overriding the default behavior nor the default value of the parameter, but it’s the main switch to tell foreman to managed the parameter, providing values to puppet or not.

Thus move the Override checkbox above the default section and make it big and clear that this checkbox enables the override for this parameter and thus all the information below is only relevant if that checkbox is checked.

Second rename “Default Behavior” to “Default Value”. It’s no behavior, you’ll define a value.

Move the “omit” checkbox to the first position in this section (i.e. move it to the place where currently the override checkbox is). Rename the omit checkbox to something like “Override default value” and the “i” tooltip to something like “Use this value instead of the puppet parameter default or class hiera data”.

I think I would immediately understand the meaning of those controls then and it’s more the expected order from the top to the bottom instead now with the omit checkbox disabling the default value textbox above.

Just some first thoughts here…

Thanks @gvde . Do you mind opening an issue on Issues · theforeman/foreman_puppet · GitHub ?

I think the main issue that needs clarification is whether this is puppet only code or whether this is something that is shared between plugins. If it is puppet-only, it is easy. If not, we might need to get creative.

O.K. See Texts and layout of override puppet class parameter gui · Issue #400 · theforeman/foreman_puppet · GitHub

1 Like