On Wednesday, October 8, 2014 2:15:09 PM UTC-5, Juan Andres Ramirez wrote:
>
> Thank you very much Felix for you replay.
> I got it now , but I have an other question:
>
> I created file findarray.pp with this code inside:
> define findarray(
> $sitearray = $title,
> $siteName
> ){
> notify{"ARRAY DEL SITIO - ${sitearray}":}
> }
>
> and call findarray from init.pp, with next code:
> $site_array = hiera("host_key")
> $prueba = keys($site_array)
>
> findarray{$prueba:
> siteName => $siteName
> }
>
> this code return only ARRAY DEL SITIO - server1 and ARRAY DEL SITIO -
> server2.
> How to get all data from hiera, why only get server1 and server2 and no
> other data?.
>
>
Why do you expect to get anything else? The keys are the only part of your
data that you give to your Findarray instances.
If you have hiera data containing a hash mapping resource names to property
hashes, then you have two pretty straightforward ways to declare the
resources thereby described:
1. You can use create_resources()
<https://docs.puppetlabs.com/references/3.7.latest/function.html#createresources>.
The data structure you already have is perfectly set up for that. I'm OK
with create_resources(), but I tend to prefer more "hands-on" approaches.
In particular,
2. If your resources are of a defined type, then you can also do something
along these lines:
class my_module {
$hosts = hiera('host_key', [])
my_module::my_host { $hosts: }
}
define my_module::my_host () {
$my_host_data = $::my_module::hosts[$title]
notify { "$title alias: ${my_host_data['alias']}": }
notify { "$title IP address: ${my_host_data['ipaddress']}": }
notify { "$title port: ${my_host_data['port']}": }
}
Another variation on that passes the whole hash as a parameter to the
defined type:
define my_module::my_host_v2 ($all_hosts_data) {
$my_host_data = $all_hosts_data[$title]
# ...
}
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/41635036-6bfc-4ccf-b930-08eda16b0a6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.