Table of Contents
Rules offer the possibility to configure a system depending on system attributes by merging multiple control file during installation. The rules based installation is controlled by a rules file.
The rules file is an XML based file that contains rules for each group of systems (or single systems) that you want to automatically install. A set of rules distinguish a group of systems based on one or more system attributes, after passing all rules, it links each group of rules to a profile. Both the rules file and the profiles must be located in a pre-defined and accessible location.
The rules file is retrieved only if no specific control is supplied using the autoyast keyword. For example, if the following is used, the rules file wont be evaluated:
autoyast=http://10.10.0.1/profile/myprofile.xml autoyast=http://10.10.0.1/profile/rules/rules.xmlinstead use
autoyast=http://10.10.0.1/profile/which will load http://10.10.0.1/profile/rules/rules.xml (the slash at the end is important)
If more than one rule apply, the final profile for each group is generated on the fly using a merge script. The merging process is based on the order of the rules and later rules override configuration data in earlier rules.
The use of a rules file is optional. If the rules file is not found, system installation proceeds in the classic way by just using the supplied profile or by searching for the profile depending on the MAC or the IP address of the system.
Example 6.1. Simple rules file
The following simple example illustrates how the rules file is used to retrieve the configuration for a client with known hardware.
<?xml version="1.0"?> <!DOCTYPE autoinstall> <autoinstall xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns"> <rules config:type="list"> <rule> <disksize> <match>/dev/hdc 1000</match> <match_type>greater</match_type> </disksize> <result> <profile>machine1.xml</profile> <continue config:type="boolean">false</continue> </result> </rule> <rule> <disksize> <match>/dev/hda 1000</match> <match_type>greater</match_type> </disksize> <result> <profile>machine2.xml</profile> <continue config:type="boolean">false</continue> </result> </rule> </rules> </autoinstall>
The last example defines 2 rules and provides a different profile for
every rule. The rule used in this case is
disksize. After parsing the rules file, YaST2
attempts to match the system being installed to the rules in the
rules.xml
file in the following order: first rule through the
last rule. A rule match occurs when the system being installed matches
all of the system attributes defined in the rule. As soon as a system
matches a rule, the result resource is added to the
stack of profiles AutoYaST will be using to create the final
profile. The continue property tells AutoYaST if it should
continue with other rules or not after a match has been found.
If the first rule does not match, next rule in the list is examined until a match is found.
Using the disksize attribute, you can provide different configurations for different hard drives with different size. First rule checks if the device /dev/hdc is available and if it is greater than 1 GB in size using the match property.
A rule must have at least one attribute to be matched. If you need to check more attributes, i.e. memory or architectures, you can add more attributes in the rule resource as shown in the next example.
Example 6.2. Simple rules file
The following simple example illustrates how the rules file is used to retrieve the configuration for a client with known hardware.
<?xml version="1.0"?> <!DOCTYPE autoinstall> <autoinstall xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns"> <rules config:type="list"> <rule> <disksize> <match>/dev/hdc 1000</match> <match_type>greater</match_type> </disksize> <memsize> <match>1000</match> <match_type>greater</match_type> </memsize> <result> <profile>machine1.xml</profile> <continue config:type="boolean">false</continue> </result> </rule> <rule> <disksize> <match>/dev/hda 1000</match> <match_type>greater</match_type> </disksize> <memsize> <match>256</match> <match_type>greater</match_type> </memsize> <result> <profile>machine2.xml</profile> <continue config:type="boolean">false</continue> </result> </rule> </rules> </autoinstall>
The rules directory must be located in the same referenced directory used with the autoyast keyword on boot time, so if the client was booted using autoyast=http://10.10.0.1/profiles/, AutoYaST will search for the rules file in http://10.10.0.1/profiles/rules/rules.xml.
If the attributes autoyast provides for rules are not enough for you, you can use custom rules. Custom rules are more or less a shell script you have to write has and whose output on STDOUT is being used to know which autoyast profile should be fetched. STDERR will be ignored.
Here is an example for the use of a custom rules:
<rule> <custom1> <script> if grep -i intel /proc/cpuinfo > /dev/null; then echo -n "intel" else echo -n "non_intel" fi; </script> <match>*</match> <match_type>exact</match_type> </custom1> <result> <profile>@custom1@.xml</profile> <continue config:type="boolean">true</continue> </result> </rule>
The script in this rule can echo either "intel" or "non_intel" to STDOUT (the output of the grep command must be directed to /dev/null in this case). Autoyast will catch that output and will fetch a file with the name "intel.xml" or "non_intel.xml". This file can contain the autoyast profile part for the software selection for example, in the case you want to do a different software selection on intel hardware than on others. So the output of the rule script will be filled between the two '@' characters, to determine the filename of the profile to fetch.
The number of custom rules is limited to 5. So you can use custom1 to custom5.
you can have five different match_types:
exact - which is the default
greater
lower
range
regex (available since 10.1 and SLES10). It's a simple "=~" operator like in bash
"greater" and "lower" can be used for memsize or totaldisk for example. They can match only on rules which return an integer value. A range is only possible for integer values too and has the form of "value1-value2", for example "512-1024". regex can be used to match substrings like "ntel" will match "Intel","intel" and "intelligent".
It's possible to combine multiple attributes via a logical operator. So it's possible to let a rule match if disksize is greater than 1GB or memsize is exact 512MB (well, not the best example maybe).
You can do that with the "operator" element in the rules.xml file. Here is an example:
<rule> <disksize> <match>/dev/hda 1000</match> <match_type>greater</match_type> </disksize> <memsize> <match>256</match> <match_type>greater</match_type> </memsize> <result> <profile>machine2.xml</profile> <continue config:type="boolean">false</continue> </result> <operator>or</operator> </rule>
Just "and" and "or" are possible operators and the default operator is "and".
The rules.xml
file must have:
At least one rule
It must have the name rules.xml
It must be located in the directory rules in the profile repository
At least one attribute to match in the rule
The following table lists the predefined system attributes you can match in the rules file.
If you are unsure about a value on your system, start an autoinstallation. If the proposal shows up, switch to the console via CTRL+ALT+F2 and run
/usr/lib/YaST2/bin/y2base ayast_probe ncurses
. It might help to to turn the confirmation on for this, so that the installation does not start in the background while you are watching the values. The textbox with the values is scrollable.
Table 6.1. System Attributes
Attribute | Values | Description |
---|---|---|
hostaddress | IP address of the host | This attribute must always match exactly |
hostname | The name of the host | This attribute must always match exactly |
domain | Domain name of host | This attribute must always match exactly |
installed_product | The name of the product that is getting installed. For example "SUSE LINUX" | This attribute must always match exactly |
installed_product_version | The version of the product that is getting installed. For example "9.3" | This attribute must always match exactly |
network | network address of host | This attribute must always match exactly |
mac | MAC address of host | This attribute must always match exactly. (MAC addresses to be matched should be in the form 0080c8f6484c |
linux | Number of installed Linux partitions on the system | This attribute can be 0 or more |
others | Number of installed non-Linux partitions on the system | This attribute can be 0 or more |
xserver | X Server needed for graphic adapter | This attribute must always match exactly |
memsize | Memory available on host in MByes | All match types are available |
totaldisk | Total disk space available on host in MBytes | All match types are available |
haspcmica | System has PCMCIA (i.e Laptops) | Exact match required, 1 for available PCMCIA or 0 for none |
hostid | Hex representation of IP address | Exact match required |
arch | Architecture of host | Exact match required |
karch | Kernel Architecture of host (i.e. SMP kernel, Athlon Kernel) | Exact match required |
disksize | Drive device and size | All match types are available |
product | The hardware product name as specified in SMBIOS | Exact match required |
product_vendor | The hardware vendor as specified in SMBIOS | Exact match required |
board | The system board name as specified in SMBIOS | Exact match required |
board_vendor | The system board vendor as specified in SMBIOS | Exact match required |
custom1-5 | Custom rules using shell scripts | All match types are available |
Since openSUSE 11.3 (not SLES11 SP1) you can use dialog popups where you can select which rules you want to match and which not by checkboxes.
The following elements must be between the <rules config:type="list"><rule><dialog> ... </dialog></rule></rules> tags in the rules.xml file.
Table 6.2.
Attribute | Values | Description |
---|---|---|
dialog_nr | all rules with the same dialog_nr are presented on the same popup dialog so the same dialog_nr can appear in multiple rules.
<dialog_nr config:type="integer">3</dialog_nr> | This element is optional and the default for a missing dialog_nr is always "0". If you have one popup only anyway, you don't need to specify the dialog_nr |
element | each element needs a uniq id. Even if you have more than one dialog, you must not use the same id twice like an id "1" on dialog 1 and and id "1" on dialog 2. That's different than with <ask> dialogs, where you can have the same <element> id on multiple dialogs.
<element config:type="integer">3</element> | optional. If left out, autoyast adds his own id's internally but you can't use conflicts then (see below) |
title | the caption of the popup dialog
<title>Desktop Selection</title> | optional |
question | the question text is shown in the popup behind the checkbox.
<question>KDE Desktop</question> | optional. If you don't configure a text here, the name of the XML file that is triggered by this rule will be shown instead. |
timeout | a timeout in seconds after which the dialog will automatically "press" the okay button. Useful for a non blocking installation in combination with rules-dialogs.
<timeout config:type="integer">30</timeout> | optional. A missing timeout will stop the installation process until the dialog is confirmed by the user. |
conflicts | a list of element id's (rules) that conflict with this rule. If this rule matches or is selected by the user, all conflicting rules are deselected and disabled in the popup. Take care that you don't create deadlocks.
<conflicts config:type="list"> <element config:type="integer">1</element> <element config:type="integer">5</element> ... </conflicts> | optional |
Here is an example of how to use dialogs with rules:
<rules config:type="list"> <rule> <custom1> <script> echo -n 100 </script> <match>100</match> <match_type>exact</match_type> </custom1> <result> <profile>rules/kde.xml</profile> <continue config:type="boolean">true</continue> </result> <dialog> <element config:type="integer">0</element> <question>KDE Desktop</question> <title>Desktop Selection</title> <conflicts config:type="list"> <element config:type="integer">1</element> </conflicts> <dialog_nr config:type="integer">0</dialog_nr> </dialog> </rule> <rule> <custom1> <script> echo -n 100 </script> <match>101</match> <match_type>exact</match_type> </custom1> <result> <profile>rules/gnome.xml</profile> <continue config:type="boolean">true</continue> </result> <dialog> <element config:type="integer">1</element> <dialog_nr config:type="integer">0</dialog_nr> <question>Gnome Desktop</question> <conflicts config:type="list"> <element config:type="integer">0</element> </conflicts> </dialog> </rule> <rule> <custom1> <script> echo -n 100 </script> <match>100</match> <match_type>exact</match_type> </custom1> <result> <profile>rules/all_the_rest.xml</profile> <continue config:type="boolean">false</continue> </result> </rule> </rules>