Kexec template not processed

Problem:
<%= snippet() %> macro in Kexec template breaks PXE-less discovery. Host errors out with:

Apr 11 11:44:55 fdi foreman-proxy[1924]: Rack::Handler::WEBrick is invoked.
Apr 11 11:44:55 fdi foreman-proxy[1924]: Initiated kexec provisioning with {“status”:“Unable to render or parse template: The specified snippet ‘current_prov_image’ does not exist, or is not a snippet.”}
Apr 11 11:44:55 fdi foreman-proxy[1924]: Downloading:
Apr 11 11:44:55 fdi foreman-proxy[1924]: Starting task: /usr/bin/wget --connect-timeout=10 --dns-timeout=10 --read-timeout=60 --tries=3 --no-check-certificate -nv -c “’’” -O “/tmp/vmlinuz”
Apr 11 11:44:55 fdi foreman-proxy[1924]: [2193] wget: unable to resolve host address ‘’’’

The template itself renders correctly and the snippets are reused without issues in other templates as well.

My kexec template: https://pastebin.com/xmiS6bXU
kexec template screenshots:
https://i.postimg.cc/Fzm6Dnds/Selection-118.png
https://i.postimg.cc/SNgPfdyk/Selection-119.png
https://i.postimg.cc/SRrv57CL/Selection-120.png
https://i.postimg.cc/05dFbxF6/Selection-121.png
https://i.postimg.cc/5N4GzTWs/Selection-122.png

current_prov_image snippet: https://pastebin.com/V0DChTEe
snippet screenshots:
https://i.postimg.cc/MTWZgwFh/Selection-123.png
https://i.postimg.cc/NFFsf4YD/Selection-124.png
https://i.postimg.cc/bJ3YhMXd/Selection-125.png
https://i.postimg.cc/gctctfqT/Selection-126.png
https://i.postimg.cc/SRPyXMxh/Selection-127.png

The preview has been generated for that exact failing host.

Expected outcome:
Host receives valid JSON and proceeds per received key values.
Foreman and Proxy versions:
Foreman 1.21 + Smart Proxy 1.21
Foreman and Proxy plugin versions:
Discovery 14.0.1 + Discovery Image 3.5.0
Other relevant data:
Both template and snippet have been imported to Foreman using foreman_templates plugin.
I tried to hand-create another snippet and use it within the template, same result.
Maybe I should update Discovery image to version 3.5.1? Gonna try that…
Same exact template/snippet working no problem with Foreman 1.19 + Discovery 13.0.1

Logs from Foreman here: https://pastebin.com/iaBL8855

Just tried Discovery Image 3.5.4, same result

Just tried with safemode rendering ON - same result.
When macro snippet() replaced with snippet_if_exists(), template gets filled with empty fields.

It just appears that all snippets are ‘invisible’ for Kexec templates…

Hello, thanks for good info. I have tested this on develop branch and it works fine. We have been redesigning template renderer during 1.20 and 1.21 and it is possible this is a regression. However I am unable to tell which change fixed it.

This has nothing to do with FDI, it’s something in Foreman app. Usually this is a problem with taxonomy, when a resource is not in the same organization or location as the host. Can you check that the location which is not assigned is not by chance assigned to the host you provision? This must always match otherwise the symptom is “not found” as our filtering stack never returns it.

Hello Lukas.
Host org/loc is NTP/Fort, nothing wrong there.
https://i.postimg.cc/1tbLnMZG/Selection-137.png

(inherited from subnet through discovery process)

make sure the kexec template is selected in Hosts->Operating Systems, Your OS, Templates->Discovery Kexec template

It’s all assigned: https://i.postimg.cc/3Js6RfjY/Selection-138.png

When you do Preview do you experience the same? This is weird.

Check Org/Loc of the host, what it belongs to again?

Sorry for the delay, I was on a vacation.

Preview works correctly for both template and snippet - please see screenshots 119 and 124.
Host org/loc is NTP/Fort (same as template and snippet).

@TimoGoebel do you think that this might be related to the snippet bug for StringTemplate you recently fixed? This is my only idea, out of anything else.

Yeah, Source::String does not allow any snippet rendering. If we want to allow snippets inside kexec templates (which I believe we want), we’d need to change these lines to

render_template(template: template)

So this should be an easy fix. I don’t have time to open a PR this week, but I’ll add it to my list.

1 Like

Thank you so much, don’t worry I will file the PR.

1 Like

@Garreat use this patch to mitigate the issue, should work with 1.21:

https://github.com/theforeman/foreman_discovery/pull/476

I hit this when testing, you don’t need this one only if you encounter argument error (this happens when exception is thrown):

https://github.com/theforeman/foreman/pull/6746

1 Like

This fixes problem, tested on 1.21.0 and 1.21.3.
Thank you!