A.3. Satellite Specific Functions and Variables

This section lists Satellite specific functions and variables for ERB templates. Note that some of them can be used in any kind of template, others are limited, for example job templates accept only @host variables and variables from Table A.4, “Kickstart Specific Variables” are only applicable in Kickstart templates.
You can use the functions listed in the following table across all kinds of templates.

Table A.1. Generic Functions

NameDescription
indent(n)Indents the block of code by n spaces, useful when using a snippet template that is not indented.
foreman_url(kind)Returns the full URL to host-rendered templates of the given kind. For example, templates of the "provision" type usually reside at http://HOST/unattended/provision.
snippet(name)Renders the specified snippet template. Useful for nesting provisioning templates.
snippets(file)Renders the specified snippet found in the Foreman database, attempts to load it from the unattended/snippets/ directory if it is not found in the database.
snippet_if_exists(name)Renders the specified snippet, skips if no snippet with the specified name is found.

Example A.1. Using the snippet and indent Functions

The following syntax imports the subscription_manager_registration snippet to the template and indents it by four spaces:
<%= indent 4 do
snippet 'subscription_manager_registration'
end %>
The following functions can be used in job templates. See Section 12.2.4, “Creating Advanced Templates” for usage examples.

Table A.2. Functions Specific to Job Templates

NameDescription
input(input_name)Returns the value of the specified input on the job execution.
render_template(name, parameters)Renders the specified template, similar to the generic snippet() function but enables passing arguments to the template.
The following variables enable using host data within templates.

Table A.3. Host Specific Variables and Functions

NameDescription
@host.architectureThe architecture of the host.
@host.bond_interfacesReturns an array of all bonded interfaces. See Note.
@host.capabilitiesThe method of system provisioning, can be either build (for example kickstart) or image.
@host.certnameThe SSL certificate name of the host.
@host.diskLayoutThe disk layout of the host. Can be inherited from the operating system.
@host.domainThe domain of the host.
@host.environmentThe Puppet environment of the host.
@host.factsReturns a Ruby hash of facts from Facter. For example to access the 'ipaddress' fact from the output, specify @host.facts['ipaddress'].
@host.grub_passReturns the host's GRUB password.
@host.hostgroupThe host group of the host.
@host.info['parameters']Returns a Ruby hash containing information on host parameters. For example, use @host.info['parameters']['lifecycle_environment'] to get the life cycle environment of a host.
@host.image_build?Returns true if the host is provisioned using an image.
@host.interfacesContains an array of all available host interfaces including the primary interface. See Note.
@host.interfaces_with_identifier('IDs')Returns array of interfaces with given identifier. You can pass an array of multiple identifiers as an input, for example @host.interfaces_with_identifier(['eth0', 'eth1']). See Note.
@host.ipThe IP address of the host.
@host.locationThe location of the host.
@host.macThe MAC address of the host.
@host.managed_interfacesReturns an array of managed interfaces (excluding BMC and bonded interfaces). See Note.
@host.mediumThe assigned operating system installation medium.
@host.nameThe full name of the host.
@host.operatingsystem.family The operating system family.
@host.operatingsystem.majorThe major version number of the assigned operating system.
@host.operatingsystem.minorThe minor version number of the assigned operating system.
@host.operatingsystem.nameThe assigned operating system name.
@host.operatingsystem.boot_files_uri(@host.medium,@host.architecture)Full path to the kernel and initrd, returns an array.
@host.os.medium_uri(@host) The URI used for provisioning (path configured in installation media).
@host.param_false?(name)Returns false if host parameter of a given name evaluates to false.
@host.param_true?(name) Returns true if host parameter of a given name evaluates to true.
@host.params['parameter_name']Returns the value of specified parameters.
@host.primary_interfaceReturns the primary interface of the host.
@host.providerThe compute resource provider.
@host.provision_interfaceReturns the provisioning interface of the host. Returns an interface object.
@host.ptableThe partition table name.
@host.puppetmasterThe Puppet master the host should use.
@host.pxe_build?Returns true if the host is provisioned using the network or PXE.
@host.shortnameThe short name of the host.
@host.sp_ipThe IP address of the BMC interface.
@host.sp_macThe MAC address of the BMC interface.
@host.sp_nameThe name of the BMC interface.
@host.sp_subnetThe subnet of the BMC network.
@host.subnet.dhcpReturns true if a DHCP proxy is configured for this host.
@host.subnet.dns_primaryThe primary DNS server of the host.
@host.subnet.dns_secondaryThe secondary DNS server of the host.
@host.subnet.gatewayThe gateway of the host.
@host.subnet.maskThe subnet mask of the host.
@host.url_for_boot(:initrd)Full path to the initrd image associated with this host. Not recommended, as it does not interpolate variables.
@host.url_for_boot(:kernel)Full path to the kernel associated with this host. Not recommended, as it does not interpolate variables, prefer boot_files_uri.
@provisioning_typeEquals to 'host' or 'hostgroup' depending on type of provisioning.
@staticReturns true if the network configuration is static.
@template_nameName of the template being rendered.
grub_passReturns the GRUB password wrapped in md5pass argument, that is --md5pass=#{@host.grub_pass}.
ks_consoleReturns a string assembled using the port and the baud rate of the host which can be added to a kernel line. For example console=ttyS1,9600.
root_passReturns the root password configured for the system.

Note

Host variables related to network interfaces, such as @host.interfaces or @host.bond_interfaces return interface data grouped in an array. To extract a parameter value of a specific interface, use Ruby methods to parse the array. For example, to get information about the first interface from an array and use it in a kickstart template:
<% myinterface = @host.interfaces.first %>
IPADDR="<%= myinterface.ip %>"
NETMASK="<%= myinterface.subnet.mask %>"
GATEWAY="<%= myinterface.subnet.gateway %>"
You can iterate over the interface array, for example to extract an array of interface names use:
<% ifnames = []
@host.interfaces.each do |i|
  ifnames.push(i.name)
end %>

Example A.2. Using Host Specific Variables

The following example checks if the host has Puppet and the Puppetlabs repository enabled:
<%
pm_set = @host.puppetmaster.empty? ? false : true
puppet_enabled = pm_set || @host.param_true?('force-puppet')
puppetlabs_enabled = @host.param_true?('enable-puppetlabs-repo')
%>
The following example shows how to capture the minor and major version of the host's operating system, which can be used for package related decisions:
<%
os_major = @host.operatingsystem.major.to_i
os_minor = @host.operatingsystem.minor.to_i
%>

<% if ((os_minor < 2) && (os_major < 14)) -%>
...
<% end -%>
The following example imports the 'kickstart_networking_setup' snippet if the host's subnet has the DHCP boot mode enabled:
<% subnet = @host.subnet %>
<% if subnet.respond_to?(:dhcp_boot_mode?) -%>
<%= snippet 'kickstart_networking_setup' %>
<% end -%>
The majority of common Ruby methods can be applied on host specific variables. For example, to extract the last segment of the host's IP address, you can use:
<% @host.ip.split('.').last %>
The following variables are designed to be used within kickstart provisioning templates.

Table A.4. Kickstart Specific Variables

NameDescription
@arch The host architecture name, same as @host.architecture.name.
@dynamic Returns true if the partition table being used is a %pre script (has the #Dynamic option as the first line of the table).
@epelA command which will automatically install the correct version of the epel-release rpm. Use in a %post script.
@mediapath The full kickstart line to provide the URL command.
@osver The operating system major version number, same as @host.operatingsystem.major.