2

我在将哈希从 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 *

我知道它希望我将参数直接实现到类中。但是,我真正想要的是资源中对我整体可用的哈希。我在这里做错了什么?

4

1 回答 1

0

First off, please don't use [] to denote an empty hash. It's not. [] is the empty array, and {} is the empty hash.

To do what you want, your data just need one more layer of hashing.

vhost_data:
    vhosts:
        project_1:            
            name: project_1
            project_name: project_1
        project_2:
            name: project_2
            project_name: project_2

Then

$data = hiera('vhost_data', {})
create_resources(project_vhosts::vhosts, $vhosts)

Of course, there is yet a simpler way to do all of that with your data.

project_vhosts::vhosts {
   'meaningless-resource-title':
       vhosts => hiera('vhosts', {})
}
于 2014-07-23T13:16:02.887 回答