Cannot render PXEGrub2 template

I have associated the “Kickstart default PXEGrub2” with CentOS 7.5. I want to rebuild the default files after a recent upgrade from 1.15 --> 1.18. However, I receive the error:

"undefined method `#operatingsystem' for NilClass:Jail (NilClass) (PXEGrub2)."

Here is a log snippet:

2018-10-02T10:23:47 [W|app|b6fe2] Cannot render 'Kickstart default PXEGrub2' | Safemode::NoMethodError: undefined method '#operatingsystem' for NilClass::Jail (NilClass) | /opt/theforeman/tfm/root/usr/share/gems/gems/safemode-1.3.5/lib/safemode/jail.rb:22:in `method_missing' | Unnamed:55:in `bind' | /opt/theforeman/tfm/root/usr/share/gems/gems/safemode-1.3.5/lib/safemode.rb:51:in `eval' | /opt/theforeman/tfm/root/usr/share/gems/gems/safemode-1.3.5/lib/safemode.rb:51:in `eval' | /usr/share/foreman/lib/foreman/renderer.rb:128:in `render_safe' | /usr/share/foreman/app/models/provisioning_template.rb:161:in `block in build_pxe_default' | /usr/share/foreman/app/models/provisioning_template.rb:153:in `each' | /usr/share/foreman/app/models/provisioning_template.rb:153:in `build_pxe_default'

It seems to be failing on the defined variables “mac” and “major”.

Here is the relevant template code:

major = host.operatingsystem.major.to_i 
mac = host.provision_interface.mac
  1. Tell Anaconda to perform network functions with boot interface
  2. both current and legacy syntax provided
    options = [“network”, “ksdevice=bootif”, “ks.device=bootif”]
    if mac
    bootif = ‘00-’ + mac.gsub(’:’, ‘-’)

Foreman and Proxy versions:

Foreman 1.18.1

The host should tell foreman to request the host’s operating system and mac but it seems to fail looking those values up. If I replace the host.operatingsystem.major.to_i with @osver is seems to get past that but fails on host.provision_interface.mac. I can seem to find an equivalent replacement for that value.

I have recently upgraded from 1.15.0 --> 1.18.1. Not sure if this would have caused some issues. I’ve setup a clustered environment and have split out the ENC and reports to separate servers. The only change in code was to modify some ruby code so that the reports would go to one server and the ENC requests would go to the other.

Note: I had to remove the ‘@’ sign in front of ‘host’ since the foreman forum does allow more than 2 users to be mentioned and it is interpreting the sign as users.

Hello @jgray and welcome to the community!

My impression is that you forgot to use @ character to access instance variable. Check the Help tab on Template edit page for more help.

major = @host.operatingsystem.major.to_i 
mac = @host.provision_interface.mac

Thanks for the reply…I mentioned in the post that I had to remove the @ sign because the foreman forum thinks those are users and as a new user, I can only reference 2 users - for whatever reason. On the actual template the @ sign is there.


Can you use any kind of pastebin service and paste the full and unchanged template?

I added the original template to pastebin:

It is the default template that comes with foreman and is locked from editing. I haven’t made any changes to it so it’s not the template itself. My guess is that the parser that is rendering the file is either corrupted or, for some reason, didn’t get updated during the upgrade process.

But that’s just a guess. I’m really not familiar enough with the Foreman to say for sure.

Does your host have operating system assigned? It looks it does not, hence the nil exception. If you deleted some OSes it might have invalid association.

Thank you for the reply. I have deleted some OSes. So that makes sense that it would try to render the file with a missing OS. However, I’m not trying to build a specific host, rather, I’m just trying to recreate the default PXE files using the “Build PXE Default” button.

I can’t see where or how an association would still be applied. What should I be looking for?

Build PXE default renders several templates but all of them do not have @host available in their contexts. I am not following how you can get this error after pressing this button. These are the templates which are being deployed via the button:

Ok…I’m a knob. I changed the global template in the settings to a custom template for some reason (I don’t remember now). Once I put them back to the global files they rendered as normal.

Thanks for pointing that out.