ERB templates allow embedding some Ruby code within the profile to modify it during the installation. With this approach, you can inspect the system and adjust the profile by setting values, adding or skipping sections, etc.
To activate the ERB processing, the profile must have the extension
.erb
(for example, autoyast.xml.erb
). Hence,
it is not possible to combine rules/classes and ERB templates.
ERB
? #Edit source
ERB
stands for Embedded Ruby and
allows using the power of the Ruby programming language to generate
different kind of contents. With ERB
, you can include
some Ruby code in your profiles to adapt them at runtime depending on the
installation system.
When using ERB, the Ruby code is enclosed between <%
and >
signs. If you want the output of the command to
be included in the resulting profile, you simply need to add an equal
sign (=
).
<bootloader> <% require "open-uri" %> <%= URI.open("http://192.168.1.1/profiles/bootloader-common.xml").read %> </bootloader>
AutoYaST offers a small set of helper functions to
retrieve information from the underlying system, like
disks
or network_cards
. You can check
the list of helpers and their values in the Section 7.2, “Template helpers”
section.
Template helpers are sets of Ruby methods that can be used in the profiles to retrieve information about the installation system.
disks
#Edit source
The disks
helper returns a list of the detected disks.
Each element of the list contains some basic information like the device name or
the size.
Key |
Type |
Value |
---|---|---|
|
String |
Device kernel name (for example, |
|
String |
Disk model |
|
String |
Serial number |
|
Integer |
Disk size (in bytes) |
|
Array<String> |
List of disk udev names. You can use any of them to refer to the device. |
|
String |
Disk vendor's name |
The profile in the example below installs the system on the largest disk.
It sorts the list of existing disks by size and takes the last one. Then it
uses the :device
key as value for the
device
element.
<partitioning t="list"> <drive> <% disk = disks.sort_by { |d| d[:size] }.last %> <!-- find the largest disk --> <device><%= disk[:device] %></device> <!-- print the disk device name --> <initialize t="boolean">true</initialize> <use>all</use> </drive> </partitioning>
network_cards
#Edit source
The network_cards
helper returns a list of network
cards, including their names, status information (for example, if they are
connected or not).
Key |
Type |
Value |
---|---|---|
|
String |
Device name (for example, |
|
String |
MAC address |
|
Boolean |
Whether the device is active or not |
|
Boolean |
Whether the device is connected or not |
|
String |
Disk vendor's name |
The following example finds the first network card that is connected to the network and configures it to use DHCP.
<interfaces t="list"> <% with_link = netword_cards.sort_by { |n| n[:name] }.find { |n| n[:link] } %> <% if with_link %> <interface> <device><%= with_link[:device] %></device> <startmode>auto</startmode> <bootproto>dhcp</bootproto> </interface> <% end > </interfaces>
os_release
#Edit source
The os_release
helper returns the operating system information,
which is included in the /etc/os-release
file.
Key |
Type |
Value |
---|---|---|
|
String |
Distribution ID (for example, |
|
String |
Distribution name (for example, |
|
String |
Distribution version (for example, |
You might use this information to decide which product to install, using pretty much the same profile for all of them (SLE or openSUSE distributions).
<products t="list"> <% if os_release[:id] == 'sle' %> <product>SLES</product> <% else %< <product>openSUSE</product> <% end %< </products>