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.
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?
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
<%
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?