Bug #36296
openTemplate render/macro for grub_pass fails
Description
When trying to add/configure grub pass at install time, it fail to render the template with a 500 server error.
From the logs the following messages (truncated) seem relevant
```
2023-04-12T18:29:42 [W|app|1be2ebbf] Error rendering the Kickstart default template
2023-04-12T18:29:42 [I|app|1be2ebbf] Backtrace for 'Error rendering the Kickstart default template' error (NoMethodError): undefined method `start_with?' for nil:NilClass
1be2ebbf | /usr/share/foreman/app/services/foreman/renderer/scope/macros/host_template.rb:127:in `grub_pass'
1be2ebbf | /opt/theforeman/tfm/root/usr/share/gems/gems/safemode-1.3.6/lib/safemode/scope.rb:37:in `method_missing'
1be2ebbf | Kickstart default:269:in `bind'
```
I've also attached a screenshot of the parameters configured.
We have set `encrypt_grub` to a boolean value of true and `grub_pass` to a string with the grub pass value.
Believe this stems from https://projects.theforeman.org/issues/32394 + https://github.com/theforeman/foreman/pull/8461
My first thought is that https://github.com/theforeman/foreman/blob/968998dbb73a975573d55f8e2d16c3437bf0bfaa/app/services/foreman/renderer/scope/macros/host_template.rb#L127 should be `host_param()` vs `host.<param>` but haven't tested.
Files
Updated by The Foreman Bot over 1 year ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/9689 added
Updated by Ben Magistro over 1 year ago
Reproduce steps (there is likely a better way for steps 2/3 but I don't know/remember it)
1) Create new host with host param `encrypt_grub` set to true and root password configured (not set on host directly, inherited from group/settings)
2) grab build token from <tfm host>/unattended/iPXE?mac=<mac>
3) open the ks path listed there
4) see error described above
Shifting the return to skip the checks it appears as if is an empty string. There is a grub pass field in the db and it defaults to empty string (https://github.com/theforeman/foreman/blob/b0cf15d79a3d3f96652cc9f75ecbec40b91e7512/db/migrate/20140912114124_add_grub_password_to_hosts.rb + https://github.com/theforeman/foreman/blob/b0cf15d79a3d3f96652cc9f75ecbec40b91e7512/db/migrate/20140912145052_add_grub_password_to_hostgroup.rb).
I would say that hints at the logic at https://github.com/theforeman/foreman/blob/b0cf15d79a3d3f96652cc9f75ecbec40b91e7512/app/models/concerns/host_common.rb#L156 always picking the grub_pass empty string value over the root pass but that code wise makes me think its only called when saving a host?