I think you are trying to use a multidimensional array within puppet. I
don't know the best way to do this, but I have used the following hack:

$ips_vlans = ['1.2.3.7/100', '1.2.3.8/200']

then within the template doing:

<% ips_vlans.each do |ipv| -%>

<% ip = ipv.split("/")[0] -%>
<% vlan = ipv.split("/")[1] -%>

<% end -%>

Yes - it is horrible. Hopefully someone has something better :-)

Joel

On Fri, Jul 10, 2009 at 2:08 AM, Gajillion <gajill...@gmail.com> wrote:

>
> I fixed the first issue of the DEVICE name by modifying my template
> like so:
>
> <% if my_type == "vlan_secondary"%>DEVICE=<%=master + '.' + name%>
> <%else -%>
> DEVICE=<%=name %>
> <% end -%>
>
> (I could have sworn I tried that before and it didn't work).
>
> Now, how do I map my IP addresses?  Do I have to create some internal
> map inside the array?
>
> On Jul 9, 10:23 am, Gajillion <gajill...@gmail.com> wrote:
> > Hi all,
> > This little exercise is pointing out huge gaps in my Puppet/Ruby
> > knowledge and I'm not sure how to get around it.  I'm working on a
> > module for writing interface files and everything works fine except
> > for my "vlan" interface creation.  Here's the snippet that's passed to
> > my definition:
> >
> >         vlan: {
> >             network::interface::nic { $name:
> >                 my_type     => "vlan_primary",
> >                 nic_type    => $nic_type,
> >             }
> >             network::interface::nic { $vlans:
> >                 my_type    => "vlan_secondary",
> >                 master      => $name,
> >                 ip          => $ip,
> >                 netmask     => $netmask,
> >                 gateway     => $gateway,
> >                 nic_type    => $nic_type,
> >             }
> >
> > $name is the name of the parent nic (eth6 for an eth6.101 tagged
> > vlan).  $vlans is an array with one or more vlan tags
> > ([ "100","101","200"]), and $ip is an array with the associated ip
> > addresses ["1.2.3.7","1.2.3.8","1.2.3.9"].
> >
> > network::interface::nic is defined as
> >
> > define network::interface::nic($my_type, $ip = "", $netmask = "",
> > $master = "", $nic_type = "Ethernet", $gateway = "",$vlan = ""){
> >     file { $name:
> >         path    => $my_type ? {
> >                         "vlan_secondary"    => "/etc/sysconfig/network-
> > scripts/ifcfg-$master.$name",
> >                         default             => "/etc/sysconfig/network-
> > scripts/ifcfg-$name",
> >                     },
> >         owner   => root,
> >         group   => root,
> >         mode    => 755,
> >         content => template("network/ifcfg"),
> >     }
> >
> > The relevant part of the ifcfg template is this:
> >
> > # Puppet managed.
> > DEVICE=<%=name %>
> > <% if ip != "" %>IPADDR=<%=ip %>
> >
> > Now, when I call this definition:
> >
> >     network::interface::setup { "eth6":
> >         ensure      => "present",
> >         ip          => ["1.2.3.7","1.2.3.8","1.2.3.9"],
> >         netmask     => "255.255.255.0",
> >         config_type => "vlan",
> >         nic_type    => "Ethernet",
> >         vlans       => [ "100","101","200"],
> >     }
> >
> > as I hope, I get the correct 4 separate files:
> >
> > [r...@buildtest network-scripts]# ls -l ifcfg-eth6*
> > -rwxr-xr-x 1 root root  83 Jul  9 11:06 ifcfg-eth6
> > -rwxr-xr-x 1 root root 141 Jul  9 11:06 ifcfg-eth6.100
> > -rwxr-xr-x 1 root root 141 Jul  9 11:06 ifcfg-eth6.101
> > -rwxr-xr-x 1 root root 141 Jul  9 11:06 ifcfg-eth6.200
> > [r...@buildtest network-scripts]#
> >
> > The device name is not what I want, but with that template code it's
> > what I expect:
> >
> > [r...@buildtest network-scripts]# grep DEVICE ifcfg-eth6*
> > ifcfg-eth6:DEVICE=eth6
> > ifcfg-eth6.100:DEVICE=100
> > ifcfg-eth6.101:DEVICE=101
> > ifcfg-eth6.200:DEVICE=200
> > [r...@buildtest network-scripts]#
> >
> > And I think I understand why the IP addresses are mangled:
> >
> > [r...@buildtest network-scripts]# grep IPADDR ifcfg-eth6*
> > ifcfg-eth6.100:IPADDR=1.2.3.71.2.3.81.2.3.9
> > ifcfg-eth6.101:IPADDR=1.2.3.71.2.3.81.2.3.9
> > ifcfg-eth6.200:IPADDR=1.2.3.71.2.3.81.2.3.9
> > [r...@buildtest network-scripts]#
> >
> > However, here's what I don't get.  I want device name to be DEVICE=
> > $master.$name.  However, adding the code
> >
> > <% if my_type == "vlan_secondary" then
> >     name = master.concat('.'.concat(name))
> > end %>
> >
> > to my template gives me an error "Failed to parse template network/
> > ifcfg: can't convert nil into String"
> >
> > Changing the code to
> >
> > <% if my_type == "vlan_secondary" then
> >         myname = master
> >         myname.concat('.'.concat(name))
> > end %>
> >
> > gives me the even more bizarre error:
> >
> > err: Could not create eth6.101.100.200: 200 already exists with name /
> > etc/sysconfig/network-scripts/ifcfg-eth6.101.100.200
> >
> > It's as if some times name equals one slice of an array and other
> > times its the whole array.  How does puppet iterate over the arrays
> > passed to it?  Is the only one processed the name variable?  Is there
> > a way to get an argument and the name variable parsed at the same
> > index?
> >
>

--~--~---------~--~----~------------~-------~--~----~
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