I'm working on building a structure for my webservers. I have my setup in hiera, but I can't seem to get puppet to give back the correct types.
In common.yaml
vhosts:
hostname:
sitename:
app_url: value
app_type: value
I have multiple sites per vhost and multiple vhosts. In my manifest I'm going to be creating the folder structure and other setup tasks, but for for now I can't even get it to iterate over the sites.
Current manifest:
define application($app_name, $app_url) {
notice("App Type: ${app_type}")
notice("App Url: ${app_url}")
}
$vhosts = hiera('vhosts')
$vhosts.each |$vhost| {
create_resources(application, $vhost)
}
The error I get is that create_resources
requires a Hash. However, if I type cast $vhost
I get that it's not a Hash but a Tuple.
How did I get a Tuple out of my yaml hash? Is there a better way to iterate over this data set to get what I need?
Why you had a tuple is explained at https://docs.puppet.com/puppet/latest/reference/function.html#each in the second example.
Given a Hiera hash like:
You can iterate over it like the following:
You can, of course, access hash values at any point like
which will result in
value
.If you are trying to do
create_resources()
, then you probably want to construct the hash as a hash of resource hashes. For example, Hiera:with Puppet: