On Monday, May 5, 2014 12:44:59 PM UTC-5, Sans wrote:
>
> Thanks John for showing me a way to do it. I haven't tried that yet but
> meanwhile, I was also trying the "define type" but different way. Do you
> think this is a better data structure?
>
> rpm_mon_base_pack:
>> base-pkg1:
>> rep: mon-repo-test
>> rpm: rpm-mon-ntp
>> ver: latest
>> base-pkg2:
>> rep: mon-utils-test:
>> rpm: rpm-mon-utils
>> ver: latest
>>
>
>
Yes, I think that's a better data structure. The import criterion here is
that the desired per-package data be selectable directly, without scanning
the whole top-level hash.
> then, in my .pp:
>
> class packages::rpm::monitoring-utils {
>>
>> $rpm_pkgs_list = hiera_array('rpm_mon_base_pack', undef)
>
>
Using hiera_array() does ensure that the value retrieved is an array, but
it's not at all what you want for this job or for either data structure.
In this case, the returned array will contain one element -- the same hash
that would be returned by the ordinary hiera() function. If the
'rpm_mon_base_pack' key appeared at multiple levels of your hierarchy, then
the array returned by hiera_array() would contain the values from the other
levels, too -- *that's* the main purpose of the funciton.
> define monitoring_utils_pkgs() {
>>
>> $i_rpm = $rpm_pkgs_list[$name]
>> $u_rpm = inline_template("<%= @i_rpm['rpm'].to_s.chomp %>")
>> $u_ver = inline_template("<%= @i_rpm['ver'].to_s.chomp %>")
>> $u_rep = inline_template("<%= @i_rpm['rep'].to_s.chomp %>")
>>
>> package { "$u_rpm":
>> ensure => $u_ver,
>> require => [
>> Yumrepo[ "$u_rep" ],
>> Package[ 'mon-tools', 'patch-utils' ],
>> ];
>> }
>> }
>> monitoring_utils_pkgs { $rpm_pkgs_list: }
>> }
>>
>
> But I end up with the error:
>
> err: Could not retrieve catalog from remote server: Error 400 on SERVER:
>> Resource title must be a String, not Hash
>>
>
>
> What's doing wrong here? I'll try your suggestion to night as well. Best!
>
The error message pretty much says it. Resource titles must be strings,
but the one element of $rpm_pkgs_list is a hash. Under slightly different
circumstances, the hash might have been automatically flattened to a
string, which would fail a bit more interestingly. An approach along those
lines could be made to work, however, by making two main changes:
1. Look up the data via hiera() rather than hiera_array(), so that the hash
is not needlessly wrapped in an array.
2. Use use just the keys of the hash as your resource titles. You can
extract an array of the keys via the stdlib's keys() function, and that's
exactly what you would want to use in your declaration:
$package_names = keys($rpm_pkgs_list)
monitoring_utils_pkgs { $package_names: }
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/ef0af391-2de0-49ea-a891-441f819496e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.