How can Red Hat Satellite snippets access variables from the calling template?

Solution In Progress - Updated -

Issue

Snippets are small templates that are called from larger main templates. When both are rendered together, the snippet's content appears inline. However, even though both the main template and the snippet are rendered together, due to variable scoping, a snippet is unable to reference a normal variable set in the calling template.

The following example is generating scoping errors or SafeMode Rendering errors when attempted.

Provisioning Template

<% myvariable = 'This is my value' -%>
<%= snippet 'mysnippet'%>

Snippet

# Oversimplified Snippet Example named:  'mysnippet'
Inside the snippet, the value set in my calling template is: <%=myvariable> %>

With SafeMode Rendering turned on, rendering the above will yield an error that SafeMode has prevented access to the variable:

There was an error rendering the oversimplified_provisioning template: ERF42-7327 [Foreman::Exception]: The snippet 'mysnippet' threw an error: Safemode doesn't allow to access 'myvariable' on #<Safemode::ScopeObject>

With SafeMode Rendering turned off, rendering the above will yield an error about an undefined variable in the snippet:

There was an error rendering the oversimplified_provisioning template: ERF42-7327 [Foreman::Exception]: The snippet 'mysnippet' threw an error: undefined local variable or method 'myvariable'

Environment

Red Hat Satellite 6

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content