Section 4.31.1, “Pre-scripts” already describes how to use a
pre-script to modify the current profile. In a nutshell, if the script
creates a /tmp/profile/modified.xml
file, AutoYaST imports
that profile and forgets about the initial one.
This is a pretty flexible approach and the only limitation is that you need to rely on the languages and libraries that are available in the installation media.
Unlike with rules, it is possible to combine ERB templates with scripts. AutoYaST will evaluate any ERB tag that you include in your script before running it. This behavior only applies to the scripts defined inside the profile and not to the external ones.
The script in the example below downloads a profile whose name is based on
the MAC address. Saving the file as
/tmp/profile/modified.xml
will cause AutoYaST to load and
use the downloaded profile.
<scripts> <pre-scripts config:type="list"> <script> <interpreter>shell</interpreter> <filename>load_profile.sh</filename> <% mac = network_cards.first > <source><![CDATA[#!/bin/bash wget -O /tmp/profile/modified.xml http://myserver/<%= network_cards.first[:mac] %>.xml ]]></source> </script> </pre-scripts> </scripts>
It is possible to use the ERB helpers in Ruby scripts. To use those helpers,
you need to require the yast
and
autoinstall/y2erb
libraries and use the
Y2Autoinstall::Y2ERB::TemplateEnvironment
class to access
them.
<scripts> <pre-scripts config:type="list"> <script> <interpreter>/usr/bin/ruby</interpreter> <filename>load_profile.rb</filename> <source><![CDATA[#!/usr/bin/env ruby require "yast" require "autoinstall/y2erb" helpers = Y2Autoinstallation::Y2ERB::TemplateEnvironment.new # Now you can use the TemplateEnvironment instance to call the helpers disk_devices = helpers.disks.map { |d| d[:device] } File.write("/root/disks.txt", disk_devices.join("\n")) ]]></source> </script> </pre-scripts> </scripts>