AUTOYAST how to modify autoyast file on the fly.
This document (7022650) is provided subject to the disclaimer at the end of this document.
Environment
SUSE Linux Enterprise Server 12 Service Pack 3 (SLES 12 SP3)
Autoyast
Situation
Purpose:
This solution address the need to build a /etc/hosts entry from separate ask variables, IP address, Hostname and domain name. Though it could have been easily done in post-script, this is a good example how an autoyast.xml can be modified on the fly.
Resolution
<ask>
<title>Customize the automatic installation</title>
<dialog config:type="integer">1</dialog>
<element config:type="integer">1</element>
<!-- remove direct assignment and use script instead
<pathlist config:type="list">
<path>networking,dns,hostname</path>
</pathlist>
//-->
<question>Enter Hostname (server name)</question>
<stage>initial</stage>
<default>linux</default>
<script>
<feedback config:type="boolean">true</feedback>
<rerun_on_error config:type="boolean">true</rerun_on_error>
<environment config:type="boolean">true</environment>
<debug config:type="boolean">true</debug>
<filename>my-host.sh</filename>
<source>
<![CDATA[
#!/bin/bash
HOSTNAME=$VAL
sed -e "s/%%HOSTNAME%%/$HOSTNAME/g" \
-e "/^\s*<ask-list/,/ask-list>$/d" \
/tmp/profile/autoinst.xml > /tmp/profile/modified.xml
]]>
</source>
</script>
</ask>... <dns>
<dhcp_hostname config:type="boolean">true</dhcp_hostname>
<domain>example.suse.de</domain>
<hostname>%%HOSTNAME%%</hostname>
---snap---
"%%HOSTNAME%%" is used as placeholder within the XML to fill in asked results.
$HOSTNAME is assigned the $VAL and used by sed command to replace and create the modified.xml.
To process 2 asks or more you need to run a script for each.
Note, # and ## work from the left end (beginning) of string,
# % and %% work from the right end.
Another example with several ask:
....
<ask-list config:type="list">
<!-- BEGIN Dialog 20 - Network -->
<ask>
<title>Customize your network settings</title>
<dialog config:type="integer">20</dialog>
<element config:type="integer">1</element>
<width config:type="integer">70</width>
<height config:type="integer">20</height>
<help><![CDATA[
<p><b>Hostname</b><br>Enter a hostname without the domain part.</p>
]]></help>
<pathlist config:type="list">
<path>networking,dns,hostname</path>
</pathlist>
<file>/tmp/may_q_hostname</file>
<question>Hostname</question>
<stage>initial</stage>
<default>linuxbox</default>
<script>
<filename>my_host.sh</filename>
<rerun_on_error config:type="boolean">true</rerun_on_error>
<environment config:type="boolean">true</environment>
<source><![CDATA[
HOSTNAME=$VAL
sed -e "s/%%HOSTNAME%%/$HOSTNAME/g" \
/tmp/profile/autoinst.xml >/tmp/profile/modified.xml
]]></source>
<debug config:type="boolean">false</debug>
<feedback config:type="boolean">true</feedback>
</script>
</ask>
<ask>
<dialog config:type="integer">30</dialog>
<element config:type="integer">1</element>
<help><![CDATA[
<p><b>Network Domain</b><br>Enter the domain for your network.</p>
]]></help>
<pathlist config:type="list">
<path>networking,dns,domain</path>
</pathlist>
<file>/tmp/may_q_dnsdomain</file>
<question>Network Domain</question>
<stage>initial</stage>
<default>example.com</default>
<script>
<filename>my_host.sh</filename>
<rerun_on_error config:type="boolean">true</rerun_on_error>
<environment config:type="boolean">true</environment>
<source><![CDATA[
DOMAIN=$VAL
sed -i -e "s/%%DOMAIN%%/$DOMAIN/g" \
/tmp/profile/modified.xml
]]></source>
<debug config:type="boolean">false</debug>
<feedback config:type="boolean">true</feedback>
</script>
</ask>
<ask>
<dialog config:type="integer">30</dialog>
<element config:type="integer">2</element>
<help><![CDATA[
<p><b>IP Address</b><br>Enter a free IP address for this host.</p>
]]></help>
<pathlist config:type="list">
<path>networking,interfaces,3,ipaddr</path>
</pathlist>
<file>/tmp/may_q_ip_addr</file>
<question>IP Address</question>
<stage>initial</stage>
<default>10.0.0.20</default>
<script>
<filename>my_ip.sh</filename>
<rerun_on_error config:type="boolean">true</rerun_on_error>
<environment config:type="boolean">true</environment>
<source><![CDATA[
IPADDR=$VAL
sed -i -e "s/%%IPADDR%%/$IPADDR/g" \
-e "/^\s*<ask-list/,/ask-list>$/d" \
/tmp/profile/modified.xml
]]></source>
<debug config:type="boolean">false</debug>
<feedback config:type="boolean">true</feedback>
</script>
</ask>
</ask-list>
.....
<host>
<hosts config:type="list">
<hosts_entry>
<host_address>127.0.0.1</host_address>
<names config:type="list">
<name>localhost</name>
</names>
</hosts_entry>
<hosts_entry>
<host_address>%%IPADDR%%</host_address>
<names config:type="list">
<name>%%HOSTNAME%%.%%DOMAIN%% %%HOSTNAME%%</name>
</names>
</hosts_entry>
<hosts_entry>
<host_address>::1</host_address>
<names config:type="list">
<name>localhost ipv6-localhost ipv6-loopback</name>
</names>
</hosts_entry>
<hosts_entry>
<host_address>fe00::0</host_address>
<names config:type="list">
<name>ipv6-localnet</name>
</names>
</hosts_entry>
<hosts_entry>
<host_address>ff00::0</host_address>
<names config:type="list">
<name>ipv6-mcastprefix</name>
</names>
</hosts_entry>
<hosts_entry>
<host_address>ff02::1</host_address>
<names config:type="list">
<name>ipv6-allnodes</name>
</names>
</hosts_entry>
<hosts_entry>
<host_address>ff02::2</host_address>
<names config:type="list">
<name>ipv6-allrouters</name>
</names>
</hosts_entry>
<hosts_entry>
<host_address>ff02::3</host_address>
<names config:type="list">
<name>ipv6-allhosts</name>
</names>
</hosts_entry>
</hosts>
</host>
Additional Information
SUSE Linux Enterprise Server 12 Service Pack 3 Autoyast Documentation
Autoyast Pre-Install Script
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.
- Document ID:7022650
- Creation Date: 09-Feb-2018
- Modified Date:03-Mar-2020
-
- SUSE Linux Enterprise Server
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com