Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 1382735 - [RFE] Allow accessing all template names for a host (in safe mode)
[RFE] Allow accessing all template names for a host (in safe mode)
Status: CLOSED ERRATA
Product: Red Hat Satellite 6
Classification: Red Hat
Component: Provisioning Templates (Show other bugs)
6.2.2
Unspecified Unspecified
medium Severity medium (vote)
: GA
: Unused
Assigned To: Daniel Lobato Garcia
Lukas Zapletal
http://projects.theforeman.org/issues...
: EasyFix, FutureFeature, Triaged
Depends On:
Blocks: 1122832
  Show dependency treegraph
 
Reported: 2016-10-07 10:29 EDT by Peter Vreman
Modified: 2018-02-21 07:35 EST (History)
8 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2018-02-21 07:35:52 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 2689971 None None None 2016-10-10 03:19 EDT
Foreman Issue Tracker 17680 None None None 2016-12-15 03:01 EST
Red Hat Product Errata RHSA-2018:0336 normal SHIPPED_LIVE Important: Satellite 6.3 security, bug fix, and enhancement update 2018-02-21 17:43:42 EST

  None (edit)
Description Peter Vreman 2016-10-07 10:29:13 EDT
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 10:54:57 EDT
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
   end

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

+  def templates_used
+    b = {}
+    available_template_kinds.map { |p| b[p.template_kind_name]=p.name }
+    b
+  end
+
   def render_template(template)
     @host = self
     load_template_vars
Comment 2 Lukas Zapletal 2016-10-13 07:46:40 EDT
Hello,

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 03:59:51 EDT
Lukas,

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.

Kickstart-6.8.1
Kickstart-6.8.2
Kickstart-6.8.3

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 03:07:58 EDT
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 03:20:40 EDT
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.

Peter
Comment 7 Lukas Zapletal 2016-10-21 09:18:04 EDT
Okay, exposing all template names should not be any problem. We will look into this.
Comment 8 Daniel Lobato Garcia 2016-12-15 02:51:13 EST
Created redmine issue http://projects.theforeman.org/issues/17680 from this bug
Comment 9 Daniel Lobato Garcia 2016-12-15 03:16:58 EST
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 04:03:17 EST
Upstream bug component is Provisioning
Comment 11 Bryan Kearney 2016-12-15 10:03:24 EST
Upstream bug component is Provisioning Templates
Comment 12 pm-sat@redhat.com 2017-01-04 12:03:14 EST
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 06:30:55 EDT
[root@zzzap ~]# rpm -q foreman katello
foreman-1.15.2-1.el7sat.noarch
katello-3.4.4-2.el7sat.noarch

Created PXELinux template:

<%= @host.templates_used %>

Result:

{"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 07:35:52 EST
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.

https://access.redhat.com/errata/RHSA-2018:0336

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