I'm having some issues with passing a hash from hiera through to a resource creation.
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', {})
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.