Bug 1382735 - [RFE] Allow accessing all template names for a host (in safe mode)
Summary: [RFE] Allow accessing all template names for a host (in safe mode)
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Provisioning Templates
Version: 6.2.2
Hardware: Unspecified
OS: Unspecified
medium vote
Target Milestone: Unspecified
Assignee: Daniel Lobato Garcia
QA Contact: Lukas Zapletal
URL: http://projects.theforeman.org/issues...
Depends On:
Blocks: 1122832
TreeView+ depends on / blocked
Reported: 2016-10-07 14:29 UTC by Peter Vreman
Modified: 2021-03-11 14:44 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2018-02-21 12:35:52 UTC
Target Upstream Version:

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 17680 0 'Normal' 'Closed' 'Allow accessing all template names for a host (in safe mode)' 2019-11-25 22:49:09 UTC
Red Hat Knowledge Base (Solution) 2689971 0 None None None 2016-10-10 07:19:06 UTC
Red Hat Product Errata RHSA-2018:0336 0 normal SHIPPED_LIVE Important: Satellite 6.3 security, bug fix, and enhancement update 2018-02-21 22:43:42 UTC

Internal Links: 1776515

Description Peter Vreman 2016-10-07 14:29:13 UTC
Description of problem:
We have multiple release of RHEL x.y and for each release there is a kickstart template. Each kcikstart template requires a different set of kernel parameters to be supplied.
We do not like to hardcode these parameters in the PXE templates because that is unmaintenable because the template logic and parameters are then separated.

This RFE would like to have the hash of templates_used[<kindname>] available in both:
- Host API
- Template rendering under @host

use case PXE template using @host.templates_used['provisioning'] to include parameters on the kernel command line that are prefixed with the provisioning template name.
default linux
label linux
  kernel <%= @kernel %>
<%= @host.inspect %>
  append initrd=<%= @initrd %> ks=<%= foreman_url('provision')%> network <%= @host.params[@host.templates_used['provisioning']+'_kernel_opts'] || "" %>  <%= @host.params['ks_kernel_opts'] || "" %>
  ipappend 2

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Set common parameter 'TemplateABC_kernel_options' with value 'ABCDEF'
2. Create provisiong template 'TemplateABC' (content not relevant)
2. Create pxe template 'PXETemplateABC' with the content below
kernel options: XXX<%= @host.params[@host.templates_used['provisioning']+'_kernel_opts'] %>ZZZ
3. Create HostA
4. Associate HostA with TemplateABC and PXETemplateABC
5. Render PXETemplateABC

Actual results:
Output of 'kernel options: XXXZZZ' where the parmaeter is empty

Expected results:
Output of 'kernel options: XXXABCDEFZZZ' where the parameter with the provisioning template name is replaced

Additional info:

Comment 1 Peter Vreman 2016-10-07 14:54:57 UTC
Proposed patch:

--- /usr/share/foreman/app/models/host/managed.rb
+++ /usr/share/foreman/app/models/host/managed.rb
@@ -74,7 +74,7 @@
       :image_build?, :pxe_build?, :otp, :realm, :param_true?, :param_false?, :nil?, :indent, :primary_interface,
       :provision_interface, :interfaces, :bond_interfaces, :bridge_interfaces, :interfaces_with_identifier,
       :managed_interfaces, :facts, :facts_hash, :root_pass, :sp_name, :sp_ip, :sp_mac, :sp_subnet, :use_image,
-      :multiboot, :jumpstart_path, :install_path, :miniroot, :medium
+      :multiboot, :jumpstart_path, :install_path, :miniroot, :medium, :templates_used

   scope :recent,      ->(*args) { where(["last_report > ?", (args.first || (Setting[:puppet_interval] + Setting[:outofsync_interval]).minutes.ago)]) }
@@ -838,6 +838,12 @@

+  def templates_used
+    b = {}
+    available_template_kinds.map { |p| b[p.template_kind_name]=p.name }
+    b
+  end
   def render_template(template)
     @host = self

Comment 2 Lukas Zapletal 2016-10-13 11:46:40 UTC

you could use Operating System - Parameters. You can set arbitrary amount of parameters for each operating system you have and use these in your PXELinux templates, or wherever you like. Example:

* Visit OS - Edit - Parameters
* Enter new parameter with name "test" and arbitrary value
* Edit PXELinux template:

KERNEL <%= @kernel %> <%= @host.params['test'] %> 

* Save, install an OS

Comment 4 Peter Vreman 2016-10-14 07:59:51 UTC

The global OS level parameters does not support lifecycles as Katello does. The OS parameter is 'Library'. But how to make the OS parameter available for a lifecycle promotion path Library-Development-QAS-Production ?

We solve this challenge of having different releases by using a templates with a version in the name and then using a specified version for each Lifeycle environment.


These are all for the same RHEL6.8, but the content of the %post is different and relies on the kernel parameters.

Comment 5 Lukas Zapletal 2016-10-17 07:07:58 UTC
Peter, I misunderstood your RFE.

Satellite 6.1 contains variable called @template_name which returns the current template name, you could use it in your code to read the parameter.

Under some conditions (when there's snippet included), the variable may contain incorrect name. This has been fixed in 6.3 version (upcoming version of Satellite).

Let me know if this gets you what you need.

Comment 6 Peter Vreman 2016-10-17 07:20:40 UTC
Hoi Lukas,

The @template_name is like you write the current template. When i render a PXE then it is the name of the PXE template.
I would like to know the name of the Provisioning template during the rendering of a PXE template.


Comment 7 Lukas Zapletal 2016-10-21 13:18:04 UTC
Okay, exposing all template names should not be any problem. We will look into this.

Comment 8 Daniel Lobato Garcia 2016-12-15 07:51:13 UTC
Created redmine issue http://projects.theforeman.org/issues/17680 from this bug

Comment 9 Daniel Lobato Garcia 2016-12-15 08:16:58 UTC
Submitted upstream as https://github.com/theforeman/foreman/pull/4115 - once it's merged I'll set to POST & propose for 6.2. Thanks Peter!

Comment 10 Bryan Kearney 2016-12-15 09:03:17 UTC
Upstream bug component is Provisioning

Comment 11 Bryan Kearney 2016-12-15 15:03:24 UTC
Upstream bug component is Provisioning Templates

Comment 12 Satellite Program 2017-01-04 17:03:14 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/17680 has been resolved.

Comment 14 Lukas Zapletal 2017-08-09 10:30:55 UTC
[root@zzzap ~]# rpm -q foreman katello

Created PXELinux template:

<%= @host.templates_used %>


{"PXELinux"=>"Kickstart default PXELinux - template used", "iPXE"=>"Kickstart default iPXE", "provision"=>"Satellite Kickstart Default", "finish"=>"Satellite Kickstart Default Finish", "user_data"=>"Satellite Kickstart Default User Data", "kexec"=>"Discovery Red Hat kexec"}

Safe-mode was enabled. Works.

Comment 18 errata-xmlrpc 2018-02-21 12:35:52 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.