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:
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
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
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.
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.
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
Okay, exposing all template names should not be any problem. We will look into this.
Created redmine issue http://projects.theforeman.org/issues/17680 from this bug
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!
Upstream bug component is Provisioning
Upstream bug component is Provisioning Templates
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/17680 has been resolved.
[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.
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