简体   繁体   English

人偶hiera和create_resource问题

[英]Puppet hiera and create_resource issue

I'm having some issues with passing a hash from hiera through to a resource creation. 我在将哈希从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)

Ignore the hidden project names :) but you get the gist. 忽略隐藏的项目名称:),但您会明白要点。 My resource looks like this: 我的资源如下所示:

define project_vhosts::vhosts(
$vhosts = []
){
    notice($vhosts)
}

I get these errors after my puppet run 人偶逃跑后出现这些错误

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 *

I get that it wants me to implement the parameters directly into the class. 我知道它希望我直接将参数实现到类中。 However what I really want is the hash available as a whole to me in the resource. 但是,我真正想要的是资源中整体上对我可用的哈希。 What am I doing wrong here? 我在这里做错了什么?

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', {})
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM