how to transfer list of interfaces from hiera to class

41 views
Skip to first unread message

Andreas Dvorak

unread,
Oct 14, 2014, 5:29:35 AM10/14/14
to puppet...@googlegroups.com
Hi,

I would like to create network interfaces with puppet.
I have
define network_interface::managed_interface(
  $device='',
  $gateway='',
  $hostname='',
  $hwaddr='',
  $ipaddr='',
  $netmask='',
  $network='',
  $up=true,
){

and
class network_interface::create_interface (
  $device = hiera(....)',
){
  managed_interface { $device:
    device  => $device,
    ipaddr  => $ipaddr,
    netmask => $netmask,
  }
}


and hiera yaml file:
network_interface:
  eth0:
    ipaddr: 10.112.67.40
    netmask: 255.255.0.0
  eth1:
    ipaddr: 10.15.67.40
    netmask: 255.255.0.0


Now I don't know how to read the hiera values in the class network_interface::create_interface. The interface names can be different.
Can some please help me?

Best regards
Andreas

Andreas Dvorak

unread,
Oct 14, 2014, 6:39:50 AM10/14/14
to puppet...@googlegroups.com
Dear all,

suddenly I found the solution:
network_interface::device_list:

  eth0:
    ipaddr: 10.112.67.40
    netmask: 255.255.0.0
  eth1:
    ipaddr: 10.15.67.40
    netmask: 255.255.0.0

class network_interface (
  $device_list={}
){
  create_resources('network_interface::managed_interface',$device_list,{})
}

define network_interface::managed_interface(
  $device=$title,

  $gateway='',
  $hostname='',
  $hwaddr='',
  $ipaddr='',
  $netmask='',
  $network='',
  $up=true,
){

Best regards
Andreas

Corey Osman

unread,
Oct 15, 2014, 4:50:50 PM10/15/14
to puppet...@googlegroups.com
Your other option if using the future parser is to use the each function and iterate around the hash like you would in any other language.

$interfaces = hiera('network_interfaces')



$interfaces.each { |$interface|
  managed_interface { $interface['device']:
    device  => $interface['name'],
    ipaddr  => $interface['ipaddr'],
    netmask => $interface['netmask'], 
  }
}


Corey
Reply all
Reply to author
Forward
0 new messages