Create/Add custom fields or column for parameters during host creation

Problem: During host creation we need to have certain host parameters to be not empty as a hard requirement. Currently there is no way in the Foreman UI to add custom required parameters.

Expected outcome: Have an option in the Foreman UI to create custom fields or a custom column in the Create Hosts page to add required fields, which can hold values that could be used inside of templates or could act as “proxy values” to set host parameters.

I will update this post with mockup of what we’re looking for.

Foreman and Proxy versions: Foreman 3.5.1

Foreman and Proxy plugin versions:

Distribution and version: RHEL 8.8

Other relevant data:

The only workaround that comes to my mind is, you define a global parameter with some value, e.g. “EMPTY” and then check in the provisioning template if the host param is EMPTY, then it should fail. That means, people would have to set the value in order for the template to render. It sounds as a great RFE, the complication is, we’d have to solve an edge case, like what happens if the host does not have the value set but someone modifies the parameter to be required afterwards. That makes the host invalid right away. I suppose the “required” attribute would be defined only on the global level, or would it make sense also e.g. on subnet/org/host group level?

Sorry for taking so long for getting back to you!

Here are two screenshots of what I’m thinking of:

Regarding your workaround: I will try this out and report back.

I’m trying to make sense of this. How can I achieve this? I have looked into the templates and tried to find ways to stop the build process right at the rendering process already but couldn’t find examples.
Would you be able to give me some pointers?

Aha! I found something. render_error(message) from the templates_doc/v1/all/ForemanRemoteExecution::Renderer::Scope::Input/render_error.en.html site of my foreman

Yes, that’s exactly what I meant. It means the template rendering will fail, which host creation form should be checking for.

So far I couldn’t get it working :confused:

I tried this in my Kickstart template

  render_error(N_('Puppet Stage is not set')) if host_param('puppet_facts_stage').nil?
  render_error(N_('Puppet Datacenter is not set')) if host_param('puppet_facts_datacenter').nil?
  render_error(N_('Puppet Group is not set')) if host_param('puppet_facts_group').nil?
  render_error(N_('Puppet Team is not set')) if host_param('puppet_facts_team').nil?

I stole this syntax from the other templates that came with Foreman.
When I clicked “create host” and then clicked “Resolve” in the “Operating System” tab for the Provisioning Templates, it was all green. I was expecting an error message. No?

Sorry for the late reply. Yes, I was expecting either that or when you click submit, that should fail as the last resort. It may be that the parameter is set to empty string though, so .nil? is always false. Perhaps try unless host_param('puppet_facts_team').present?

Sorry for the late reply.

No worries :slight_smile:

Perhaps try unless host_param('puppet_facts_team').present?

I will give this a go tomorrow and report back!

Just to be clear:

  render_error(N_('Puppet Stage is not set')) unless host_param('puppet_facts_team').present?

is what you were thinking, right?

Correct, as long as present is in safe mode, that should do the trick

No luck :confused:

What do you mean by “present is in safe mode”? I checked and I have “Safemode rendering” to Yes.

Does it matter where I put in this check? I wanted to use it in Kickstart default custom post.

I now thought maybe I was using the method wrong and checked to see which other templates use the render_errror method and found “Module Action - SSH Default”.

This has the following lines:

  supported_families = ['Redhat']
  render_error(N_('Unsupported or no operating system found for this host.')) unless @host.operatingsystem && supported_families.include?(

I copied them and adapted the text to say

  supported_families = ['Windows']
  render_error(N_('Unsupported or no operating system found for this host.')) unless @host.operatingsystem && supported_families.include?(

When deploying a Red Hat VM I was expecting it to fail, even to fail early when clicking to “resolve” the provisioning templates:

but it did not fail or show a warning unfortunately.