Hi all

I've got node definition on the site with server interface, bonding and 
TCP/IP configurations inscribed in a per-node [ hash + accompanying 
array-of-interface-names ]
(e.g. $array = [ 'eth0', 'eth1' ]
$hash = { 
   eth0 => { 
      ipaddress => 1.2.3.4, 
      ... }
   eth1 => { 
      ipaddress => 5.6.7.8,
      ... }
}

What I have right now works, but is clunky and could probably be written 
better.

My 2 questions are:
1. Can I somehow get a list of keys from the hash itself (a list that will 
behave like an array that I can feed into a defined type) instead of 
"manually" defining $array for this purpose?

2. If you look further down inside in this post, the code (taken from inside 
the base class) does this:
[a] gets the hash with the configuration passed in as a global variable
[b] copies the hash elements into local variables (because a local variable 
can be double-quoted around, and behave nicely even if it wasn't set and is 
blank, whereas a hash element cannot)
[c] invokes the interface-configuration defined type with the local 
variables as parameters.
A very messy roundabout way of doing things. Can anyone suggest an easier 
way (tho still ultimately has to call base::network-common::interface)

In the node file I have a configuration block that looks like this:
        $netiflist      = [ 'eth0' ]
        $netifcfg       = {
                eth0 => {      ipaddress => "1.2.3.4",
                                netmask => "255.255.255.0",
                                gateway => "1.2.3.1",
                                defaultgateway => "yes" },
        }
        include base

Then in a subclass of base I have:

class base-subclass {
# Iterate for all the interfaces that need to be configured:
if $netiflist           { base::network-common::dointerfaces 
{[$netiflist]:}}
}

# the actual defined type:
define base::network-common::dointerfaces() {
      # copy hash elements into local variables:
        $myipaddress       = $netifcfg[$name][ipaddress]
        $mynetmask         = $netifcfg[$name][netmask]
        $mygateway         = $netifcfg[$name][gateway]
        $mydefaultgateway  = $netifcfg[$name][defaultgateway]
        $myhwaddress       = $netifcfg[$name][hwaddress]
        $myroutes          = $netifcfg[$name][routes]
        $myensure          = $netifcfg[$name][ensure]

# and finally use the double-quoted local variables to call the interface 
defined type:
        base::network-common::interface { $name:
                ipaddress       =>      "$myipaddress",
                netmask         =>      "$mynetmask",
                gateway         =>      "$mygateway",
                defaultgateway  =>      "$mydefaultgateway",
                hwaddress       =>      "$myhwaddress",
                routes          =>      "$myroutes",
                ensure          =>      "$myensure"
        }
}
...



-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to