On Wednesday, June 24, 2015 at 6:31:06 AM UTC-5, Albert Shih wrote:
>
> Le 19/06/2015 à 05:59:54-0700, jcbollinger a écrit
>
[...]
> >
> > There are many examples of this sort of thing available on the Forge and
> > elsewhere. If you want more concrete advice, then pose a more concrete
> > question.
>
> Well let's say I have a server with a lot of Vhost (apache). So I used
>
> apache::vhost { 'vhost1':
> }
>
> apache::vhost { 'vhost2':
> }
>
> etc..
>
> what I want is to have inside one variable the list of all my vhost (event
> by patching puppetlabs/apache module.
>
>
Yes I can create a huge hiera config but that's going to be very hard to
> maintain because apache::vhost get lot of params. So I'm going to need to
> create a very big hiera file.
>
>
You can create a huge hiera file, or you can create a huge manifest file.
The size of the data is whatever it is, and you have to put it *somewhere*.
Externalizing it separates the data representation from the logic, making
both easier to understand and maintain. Moreover, externalizing the data
can make the logic you want to express easier to write.
One way to approach this would be to structure the data for use with
Puppet's create_resources() function. In YAML, the data would look
something like this:
mymodule::apache::vhosts:
vhost1:
param1: value
param2: another_value
vhost2:
param1: different_value
param2: blah
The corresponding manifest code (Puppet 3 style) could be:
class mymodule::apache ($vhosts = {}) {
include 'apache'
# The keys() function is from puppetlabs-stdlib
$vhost_list = keys($vhosts)
# create_resources() is a built-in
create_resources('apache::vhost', $vhosts)
}
The manifest code does not have to change when you change the data, and you
can use any and all of Hiera's features to influence what data actually are
presented for each node.
If you want more clarity or control over what's going on, then it is
straightforward to replace create_resources() with DSL code, though such
code will be specific to the resource type for which you want to create
instances, and it will have to provide explicitly for every parameter of
that resource type that you care about.
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/496e651c-ff12-49dc-b41e-1d9ba8df5c9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.