我在从hiera传递哈希到资源创建时遇到了一些问题。
vhosts:
project_1:
name: project_1
project_name: project_1
project_2:
name: project_2
project_name: project_2
$vhosts = hiera('vhosts', [])
create_resources(project_vhosts::vhosts, $vhosts)
忽略隐藏的项目名称:)但是你得到了要点。我的资源看起来像这样:
define project_vhosts::vhosts(
$vhosts = []
){
notice($vhosts)
}
我得到这些错误后,我的木偶运行
Error: Invalid parameter project_name on project_vhosts::Vhosts[project_1] on node *
Wrapped exception:
Invalid parameter project_name
Error: Invalid parameter project_name on project_vhosts::Vhosts[project_1] on *
我知道它想让我直接在类中实现参数。然而,我真正想要的是资源中可用的哈希值。我哪里做错了?
首先,请不要使用[]
来表示空散列。它不是。[]
为空数组,{}
为空散列。
要做你想做的,你的数据只需要多一层哈希。
vhost_data:
vhosts:
project_1:
name: project_1
project_name: project_1
project_2:
name: project_2
project_name: project_2
然后$data = hiera('vhost_data', {})
create_resources(project_vhosts::vhosts, $vhosts)
当然,还有一种更简单的方法来处理数据。
project_vhosts::vhosts {
'meaningless-resource-title':
vhosts => hiera('vhosts', {})
}