【发布时间】:2019-07-19 11:40:36
【问题描述】:
更新 1
我稍微改变了 Hiera 数据的结构并尝试了不同的清单样式。
我正在尝试在 Puppet 清单中迭代以下 Hiera 哈希:
windows-10.yaml:
---
message: "This node is using Windows 10 data"
#profile::hiera_test::backups_enabled: false
profile::hiera_test::firewall:
rule1:
groupName: 'Cortana'
profileNames: ['Private','Public']
action: 'Deny'
rule2:
groupName: 'Microsoft Photos'
profileNames: 'Public'
action: 'Deny'
虽然我已经更新了数据结构并且puppet lookup... 返回了似乎有效的内容,但我对这个结构并不完全有信心。
我尝试了清单的多种排列方式。最新的如下所示(基于 Matt Schuchard 给出的this 回答):
hiera_test.pp:
class profile::hiera_test (
Hash $data = lookup('profile::hiera_test::firewall', "merge" => 'hash'),
){
$data.each | String $key, Hash $value = {}|{
notify {
default:
name => "Demo_${key}",
message => 'Item DEFAULT',
;
$key:
* => $value,
}
}
}
以及上面的错误/输出:
PS C:\Users\LocalAdmin> puppet agent -t
Notice: Local environment: 'production' doesn't match server specified node environment 'development', switching agent to 'development'.
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: no parameter named 'groupName' (file: /etc/puppetlabs/code/environments/development/site-modules/profile/manifests/hiera_test.pp, line: 31) on Notify[rule1] (file: /etc/puppetlabs/code/environments/development/site-modules/profile/manifests/hiera_test.pp, line: 31) on node winnode1.domain.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
理想情况下,我希望它在类声明中工作(为什么?因为这大约是我的 Puppet 学习所能达到的程度,但很高兴进一步学习。我也在使用 Puppet Enterprise (2019.0.2)) .
互联网上有几个类似的问题,但它们要么已经过时(Hiera this,要么我不知道如何将它们转换成我需要的。显然create_resources 是由于折旧
?
如果有人能告诉我哪里出错了,那就太好了。
【问题讨论】:
-
我们可以自己测试您使用代码获得的结果并猜测您想要达到的目标,但您可以分享这两个结果,以便我们在这里提供最好的帮助吗?