On Friday, May 2, 2014 4:46:56 PM UTC-5, Sans wrote:
>
> In my module, I have something like this to installed some base packages:
>
> package {
>> 'rpm-mon-ntp':
>> ensure => latest,
>> require => Yumrepo[ "mon-repo-test" ];
>>
>> 'rpm-mon-utils':
>> ensure => installed,
>> require => Yumrepo[ "mon-utils-test" ];
>>
>> 'rpm-mon-patch':
>> ensure => installed,
>> require => [
>> Yumrepo[ "mon-repo-test" ],
>> Package[ 'mon-tools', 'patch-utils' ],
>> ];
>> }
>>
>
> I want to use hiera to supply the values - repo-name, rpm-name, version
> etc. Is it possible at all?
> I suppose, in the .yaml I can have something like this (in
> {repo-name{rpm-name:
> version}} format) :
>
>
> rpm_mon_base_pack:
>> mon-repo-test:
>> rpm-mon-ntp: latest
>> rpm-mon-patch: installed
>>
> mon-utils-test:
>> rpm-mon-utils: latest
>>
>
>
> but then, how do I do to make the package{} to get the values from hiera?
> How do I handle the case when Package[] is also required? Any
> help/pointer?
>
>
You can use the create_resources() function to declare resources based on
hashes similar in form to those you present. You cannot, however, express
resource references in hiera data, and you need resource references to
express your resource relationships. That can be worked around. In this
case, you also structure your data in a form that is not particularly
conducive to the lookups you want to perform, but that, too can be worked
around.
As is often the case in Puppet DSL, a suitable defined type can serve here
as an adaptor, and suitable templates can do the needed processing. I
might do something like this:
define site::hiera_package($package_pack) {
$repo = inline_template("<%= @package_pack.values.each { |repo| if
repo.has_key?(@name) { repo; break } } %>")
if $repo == '' {
fail("No package '@name' defined in the provided pack")
}
package { $name:
ensure => $package_pack[$repo][$name]
require => Yumrepo[$repo]
}
}
That will work with the data structure you presented, but will not provide
relationships on other Packages. However, since you are assuming the Yum
package provider, you should not need to define package relationships to
Puppet. These should already be adequately described in your packages'
internal metadata, which Yum uses to install any needed dependencies
automatically.
If you nevertheless want data-driven explicit dependencies between
packages, then you can probably obtain that. One approach would involve
making the values of the inner hashes be a third level of hash wherein you
describe possibly-multiple properties of the package named by the key. One
of those properties would be the state to ensure, and another could be an
array of the names of packages it should depend on. You could then use an
additional define to process the array and declare appropriate resource
relationships via a chain operator. Alternatively, the iteration
facilities of the Future parser might provide a more direct route to
expressing the needed chain operations.
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/58492060-2180-4850-8228-d774afb7a562%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.