gpt4 book ai didi

linux - 将哈希传递给 puppet/erb 中定义的类型

转载 作者:太空狗 更新时间:2023-10-29 12:34:43 27 4
gpt4 key购买 nike

我第一次尝试在 puppet 中使用哈希,所以在我的 nodes.pp 中我将使用这个:

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...}

我的问题是如何将散列的每个键传递给定义的类型?不知何故,我想象我将不得不在某处创建一个循环,任何帮助都会有很大的帮助。

谢谢丹

最佳答案

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'
}

关于linux - 将哈希传递给 puppet/erb 中定义的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14816078/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com