Need help with ERB Template

Problem:
I’m moving from satellite 6.3 to satellite 6.5, and we’ve got several custom templates.
The are differences in syntax that are causing issues.
For instance this code in the 6.3 environment works:
<%- @host.params[‘common_packages’].each_line do |package| -%>

But in the 6.5 environment I get:

undefined method '#params' for Host::Managed::Jail.

I found the following site online:

And based on that I converted similar references to use:
host_param(‘common_packages’), but as you can see from the original there’s more to the story that just getting all of the parameters.
In the original code it looks more like:
<% os_major = @host.operatingsystem.major.to_i %>
<%- @host.params[‘common_packages’].each_line do |package| -%>
<%= package.strip -%>

I know nothing of ERB, Ruby, etc., so I’m really struggling with converting the code.

I’m looking through templates provided by Red Hat, and might eventually get to a point where I’m might be able to cobble enough of it together, but am trying to get some help.

Expected outcome:

Working templates :slight_smile:

Foreman and Proxy versions:
foreman-gce-1.20.1.35-1.el7sat.noarch
foreman-cli-1.20.1.35-1.el7sat.noarch
foreman-installer-katello-3.10.0.8-1.el7sat.noarch
foreman-ec2-1.20.1.35-1.el7sat.noarch
foreman-selinux-1.20.0-1.el7sat.noarch
foreman-vmware-1.20.1.35-1.el7sat.noarch
foreman-postgresql-1.20.1.35-1.el7sat.noarch
foreman-openstack-1.20.1.35-1.el7sat.noarch
foreman-1.20.1.35-1.el7sat.noarch
foreman-rackspace-1.20.1.35-1.el7sat.noarch
foreman-installer-1.20.0-2.el7sat.noarch
foreman-proxy-1.20.0-1.el7sat.noarch
foreman-ovirt-1.20.1.35-1.el7sat.noarch
foreman-bootloaders-redhat-201801241201-4.el7sat.noarch
foreman-compute-1.20.1.35-1.el7sat.noarch
foreman-bootloaders-redhat-tftpboot-201801241201-4.el7sat.noarch
foreman-libvirt-1.20.1.35-1.el7sat.noarch
foreman-debug-1.20.1.35-1.el7sat.noarch

Foreman and Proxy plugin versions:

Other relevant data:
[e.g. logs from Foreman and/or the Proxy, modified templates, commands issued, etc]
(for logs, surround with three back-ticks to get proper formatting, e.g.)

logs

It dawned on me that I should post the complete code.
So here it is…

<%#
kind: snippet
name: APC Software Packages
%>
<% os_major = @host.operatingsystem.major.to_i %>
<%- @host.params[‘common_packages’].each_line do |package| -%>
<%= package.strip -%>

<%- end -%>
<% if os_major == 7 -%>
<%- @host.params[‘rhel7_packages’].each_line do |package| -%>
<%= package.strip -%>

<%- end -%>
<% else -%>
<%- @host.params[‘rhel6_packages’].each_line do |package| -%>
<%= package.strip -%>

<%- end -%>
<% end -%>

Doing a bit more research I came across this discussion.

Betting this is what is getting me.

Still not entirely sure how to address though.

Hello and welcome to the community! In Satellite 6.4 we’ve changed the user interface to params. You will need to modify all your templates, here is an example:

@host.params['parameter1'] -> host_param('parameter1')
@host.param_true?('parameter1') -> host_param_true?('parameter1')
@host.param_false?('parameter1') -> host_param_false?('parameter1')
@host.info['parameters']['realm']  -> host_enc['parameters']['realm']

More info in the 6.5 Release Notes or:

Just to add an example based on your code

should be changed to

<%- host_param(‘common_packages’).each_line do |package| -%>

Note that we plan to reintroduce host_param macro to access host params on host object, so in 1.24+ due to report template usage, you’ll be able to write something like @host.host_param('common_packages')

Thanks @lzap!

@Marek_Hulan - Thank you! I’ll make those adjustments.

Just an update.
I modified my templates as described and things are looking much better!

As an example, this was what I started with:

<%#
kind: snippet
name: APC Software Packages
%>
<% os_major = @host.operatingsystem.major.to_i %>
<%- @host.params['common_packages'].each_line do |package| -%>
<%= package.strip -%>

<%- end -%>
<% if os_major == 7 -%>
<%- @host.params['rhel7_packages'].each_line do |package| -%>
<%= package.strip -%>

<%- end -%>
<% else -%>
<%- @host.params['rhel6_packages'].each_line do |package| -%>
<%= package.strip -%>

<%- end -%>
<% end -%>

This is what I have now:

<%#
kind: snippet
name: APC Software Packages
%>
<% os_major = @host.operatingsystem.major.to_i %>
<%- host_param('common_packages').each_line do |package| -%>
<%= package.strip -%>

<%- end -%>
<% if os_major == 7 -%>
<%- host_param('rhel7_packages').each_line do |package| -%>
<%= package.strip -%>

<%- end -%>
<% else -%>
<%- host_param('rhel6_packages').each_line do |package| -%>
<%= package.strip -%>

<%- end -%>
<% end -%>

I think I’m past the syntax errors (changes) in my templates.