Templates (was: FAI and yaml [Work in progress])

Thomas Neumann blacky+fai at fluffbunny.de
Wed Jul 21 18:35:25 CEST 2010


hiya

I was thinking a bit more about templates and now I'm convinced this is 
definitely the way to go.
However I'd like to propose a change. Please give feedback.

This is the format Thomas describes in his example:
<http://faiwiki.informatik.uni-koeln.de/index.php/FaiTemplates>
#############################################################
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
auto lo
iface lo inet loopback

[% FOREACH name = interfaces.keys.sort %]
[% i = interfaces.$name -%]
auto [% name %]
iface [% name %] inet static
         address   [% i.address %]
         netmask   [% i.netmask %]
        [% IF i.network   %] network   [% i.network   %] [% END %]
        [% IF i.broadcast %] broadcast [% i.broadcast %] [% END %]
        [% IF i.gateway   %] gateway   [% i.gateway   %] [% END %]

[% END %]
#############################################################

I'd like to suggest a small addition - an optional meta header.
(I removed the loop for easier understanding.)

Let's assume "iface0.address", "iface1.address" are somehow available.

Please note the introduction of "classes:" - it should specifiy a 
condition when this template is appliccable.
#############################################################
---meta---
mode: 644
user: root
group: root
classes: OS_DEBIAN WEBSERVER
---body---
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
         address   [% iface0.address %]
         netmask   [% iface0.netmask %]
         if-up route add -net 10.0.0.0 netmask 255.0.0.0 gw [% 
iface0.gateway %]

auto eth1
iface eth1 inet static
         address   [% iface1.address %]
         netmask   [% iface1.netmask %]
         gateway   [% iface1.gateway %]
#############################################################
-- /etc/network/interfaces

Let's have a look at SuSE:
(I only list the config file for eth0.)

#############################################################
---meta---
mode: 644
user: root
group: root
classes: OS_SUSE WEBSERVER
---body---
BOOTPROTO='static'
MTU=''
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'
IPADDR='[% iface0.address %]'
NETMASK='[% iface0.netmask %]'
BROADCAST=''
ETHTOOL_OPTIONS=''
NAME=''
NETWORK=''
#############################################################
-- /etc/sysconfig/network/ifcfg-eth0

This works with SLES11, but not with SLES10. SLES10 expects the filename 
to be in the form /etc/sysconfig/network/ifcfg-eth-id-<mac address>. 
Let's make it variable!

#############################################################
---meta---
filename: /etc/sysconfig/network/ifcfg-eth-id-[% iface0.mac %]
mode: 644
user: root
group: root
classes: OS_SUSE OS_SUSE10 WEBSERVER
---body---
BOOTPROTO='static'
MTU=''
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'
IPADDR='[% iface0.address %]'
NETMASK='[% iface0.netmask %]'
BROADCAST=''
ETHTOOL_OPTIONS=''
NAME=''
NETWORK=''
#############################################################

Now even the filename is templatable - exactly what I need.
This mechanisme also enables me to write a /etc/sysconfig/network/routes 
for SLES10 and /etc/sysconfig/network/ifroute-eth0 / 
etc/sysconfig/network/ifroute-eth1 for SLES11.

... or any other file that is distribution specific.

tschüß
thomas


More information about the linux-fai mailing list