We use embedded Ruby to make our provisioning templates more dynamic; and it’s been working reliably, so thanks to the people who made this possible.
Problem:
We are experiencing a bug in the templates preview - or we need some more explanation. Developing snippet code (which isn’t yet used inside any template) on the fly by switching between editor and preview, the preview renders in some unexpected ways. Please see examples below.
Background: An external system (vRealize Orchestrator) writes the JSON-formatted host parameter “storages” to each host. A snippet is used to iterate over this structure. The aim is to use this information in order to format lvm-based disks automatically.
Expected outcome:
- Previewing below snippet for a host with below parameter, the sub-items contained in “storages” are only accessed if safe mode is enabled. In normal mode, only the “debug” line is rendered. Shouldn’t safe mode display less (potentially dangerous) code than normal mode?
- Notice the “print” line at the end of the snippet? It has no function, but if we leave it out the “debug” line is printed twice and the line which represents the output of the for loop disappears. Why that?
- As safe mode only shows the lines which would be printed encapsulated in brackets, is there a way to use normal mode, so that we could see the actual line breaks?
Foreman and Proxy versions:
both 3.5.3
Foreman and Proxy plugin versions:
not applicable
Distribution and version:
RHEL 8
Other relevant data:
example: parameter “storages”
[{"size":30,"mountpoint":"/","diskUuid":"6000C29..."},
{"size":50,"mountpoint":"/db","diskUuid":"6000C29..."},
{"size":10,"mountpoint":"/pkg","diskUuid":"6000C29..."}]
example: snippet “lvm”
<%#
kind: snippet
name: lvm
model: ProvisioningTemplate
snippet: true
-%>
<%# debug: check that the parameter is populated -%>
<%= host_param('storage') %>
<%=
lvm = host_param('storage')
for item in lvm do
print item["size"]
print item["mountpoint"]
print item["diskUuid"]
end
print
%>
rendered preview (safe mode):
[{"size"=>30, "mountpoint"=>"/", "diskUuid"=>"6000C29..."}, {"size"=>50, "mountpoint"=>"/db", "diskUuid"=>"6000C29..."}, {"size"=>10, "mountpoint"=>"/pkg", "diskUuid"=>"6000C29..."}]
[30]["/"]["6000C29..."][50]["/db"]["6000C29..."][10]["/pkg"]["6000C29..."][]