2013-02-11 57 views
2

我试图使用哈希在木偶的第一次,所以我nodes.pp我将使用:传递一个哈希在木偶/定义的类型ERB

node test1.example.com { 
    netset::int::vconf {"servers" : 
     label1 => { 'comment' => 'VIP Test1', 'ipaddress' => '192.168.1.10', 'netmask' => '255.255.255.0', 'int_label' => 'TEST1' }, 
     label2 => { 'comment' => 'VIP Test2', 'ipaddress' => '192.168.1.11', 'netmask' => '255.255.255.0', 'int_label' => 'TEST2' }, 
    } 
} 

在我写我创建一个定义类型的文件/etc/puppet/modules/netset/int/vconf.pp:

define netset::int::vconf ($comment,$ipaddress){...do somethings...} 

我questionis我怎么通过散列的每个键的定义类型?不知何故,我想象着我将不得不在某处创建一个循环,任何帮助都会有很大的帮助。

谢谢丹

回答

1

Puppet(还)不支持循环。所以你基本上想要的是创建一个散列并将它传递给puppet函数“create_resources()”。所以,在你的情况下,它看起来是这样的:

$my_hash = { 
    'label1' => { 
    'comment' => 'VIP Test1', 
    'ipaddress' => '192.168.1.10', 
    'netmask' => '255.255.255.0', 
    'int_label' => 'TEST1' 
    }, 
    'label2' => { 
    'comment' => 'VIP Test2', 
    'ipaddress' => '192.168.1.11', 
    'netmask' => '255.255.255.0', 
    'int_label' => 'TEST2' 
    }, 
} 

而在这之后:

create_resources(::netset::int::vconf, $my_hash) 

因此,它基本上是一样的,如果你写了这样的事情:

::netset::int::vconf { 'label1' : 
    'comment' => 'VIP Test1', 
    'ipaddress' => '192.168.1.10', 
    'netmask' => '255.255.255.0', 
    'int_label' => 'TEST1' 
}, 

::netset::int::vconf { 'label2' : 
    'comment' => 'VIP Test2', 
    'ipaddress' => '192.168.1.11', 
    'netmask' => '255.255.255.0', 
    'int_label' => 'TEST2' 
}