Xavier Beaudouin wrote:
> Assuming I have eth0 given by a dhcp I''d like to setup it to
static
> ip... and
>
> eth1
> eth2
> eth3
>
> to another IP as well.
>
> For example facter gave me ipaddress => 172.16.20.11
<http://172.16.20.11>
>
> so eth0 will have 172.16.20.11 <http://172.16.20.11>, with gateway
.254
> eth1 will have 172.17.20.11 <http://172.17.20.11>
> eth2 will have 172.18.20.11 <http://172.18.20.11>
> and
> eth3 will have 172.19.20.11 <http://172.19.20.11>..
>
> Now I don''t know how to extract "last" number of IPv4
address and if
> there is nice way on RHEL4 with puppet to set interfaces without rewrite
> files "by hand" with puppet.
There are two parts to this question. The first is how to calculate the
addresses for eth1, eth2 and eth3 from the address of eth0, and the other
is how to actually configure eth1, eth2 and eth3.
For the first part, your question inspired me to write a custom function,
which I named regsubst(), for doing regexp replacement on text strings.
I have attached that one for your use. With it, you can do:
$ipre = ''^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$''
$i1 = regsubst($ipaddress_eth0, $ipre, ''\1'')
$i2 = regsubst($ipaddress_eth0, $ipre, ''\2'')
$i3 = regsubst($ipaddress_eth0, $ipre, ''\3'')
$i4 = regsubst($ipaddress_eth0, $ipre, ''\4'')
Now you have the four octets from the eth0 address in $i1, $i2, $i3 and $i4,
respectively. If you use Puppet 0.24.6 (or later, presumably), you can
then do
$i2_1 = $i2 + 1
$i2_2 = $i2 + 2
$i2_3 = $i2 + 3
$ip_1 = "$i1.$i2_1.$i3.$i4"
$ip_2 = "$i1.$i2_2.$i3.$i4"
$ip_3 = "$i1.$i2_3.$i3.$i4"
after which you have the new addresses in $ip_1, $ip_2 and $ip_3. The
variables $i2_1, $i2_2 and $i2_3 are just intermediaries that I don''t
think you can get away without.
For actually configuring eth1, eth2 and eth3, I use a custom define:
define rh_interface($bootproto="static",
$ipaddress="",
$netmask="",
$gateway="",
$onboot="yes",
$ensure="up",
$persistent_dhcp="yes")
{
file {
"/etc/sysconfig/network-scripts/ifcfg-$name":
content => template("FILES/rh-ifcfg.erb"),
owner => "root", group => "root", mode =>
0444,
notify => Exec["rh_interface--ifconfig--$name/$ensure"];
}
case $ensure {
"up": {
exec {
"rh_interface--ifconfig--$name/up":
command => "/sbin/ifdown ''$name'' &&
/sbin/ifup ''$name''",
refreshonly => true,
path => "/bin:/usr/bin:/sbin:/usr/sbin";
}
}
"down": {
exec {
"rh_interface--ifconfig--$name/down":
command => "/sbin/ifdown ''$name''",
refreshonly => true,
path => "/bin:/usr/bin:/sbin:/usr/sbin";
}
}
default: {
fail("Bad ensure parameter to rh_interface $title: $ensure")
}
}
}
This is RedHat specific; it won''t work on for example Gentoo, Solaris,
or Debian. It uses an ERB template to do its job, which I have also
attached (rh-ifcfg.erb). You need to change that path to it in the
definition above.
(Puppet used to have a resource type for defining network interfaces.
Unfortunately it didn''t work, and was removed a while ago. Hopefully
Puppet will develop a new interface type, that actually works.)
Using rh_interface, you can then do
rh_interface {
"eth1": ipaddress => $ip_1, netmask => "255.255.0.0";
"eth2": ipaddress => $ip_2, netmask => "255.255.0.0";
"eth3": ipaddress => $ip_3, netmask => "255.255.0.0";
}
in your node definitions.
Thank you for giving me the inspiration to do this! I have actually
wanted to do precisely this, but never got around to implement something
that worked. (My use case was giving IP addresses to Infiniband
interfaces. Neither ISC dhcpd, nor the dhclient program that ships
with Fedora/RHEL/CentOS, can handle Infiniband networks.)
Hope this helps.
/Bellman
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---