On Thursday, June 18, 2015 at 9:17:10 AM UTC-5, Albert Shih wrote:
>
> Le 12/06/2015 à 07:06:49-0700, jcbollinger a écrit 
> > 
> > You don't.  If you were willing to write a custom function or possibly 
> to 
>
> That' sucks ... 
>
> > engage in some ruby-fu inan inline template then you could extract a 
> list of 
> > the titles of all Things::Addthing resources declared to that point 
> during 
> > catalog building, but that's not necessarily the same thing, as 
> instances may 
> > have been declared elsewhere, too. 
>
> Exactly. 
>


So what made you think anything along these lines could work, then?  The 
data you wanted to extract is nowhere recorded, and I'm uncertain why you 
supposed it would be otherwise.

 

>
> > More generally, it is never a good idea for your manifests to rely on 
> > extracting data from the catalog under construction. The result of any 
> such 
> > inquiry is necessarily dependent on the order in which Puppet evaluates 
> your 
>
> In fact the order don't matters for me. 
>


It absolutely *does* matter to you if the outcome of the catalog-building 
process depends on that order.  It is undesirable for that to be the case, 
but the closest thing available to what you asked for would produce that 
result.

 

>
> > manifests, which is difficult to predict.  Instead, focus on data first, 
> and 
> > code second.  For example, if you want a list of the Thing::Addthings, 
> then 
> > start with that, and use it to make your declarations, instead of making 
> your 
> > declarations and after the fact trying to determine what you declared 
> (which in 
> > truth you already know anyway): 
> > 
> > class my_service { 
> >   include ::things 
> > 
> >   $thinglist = [ 'first', 'second', 'third' ] 
> > 
> >   things::addthing { $thinglist: } 
> > } 
> > 
> > It's shorter, too. 
>
> Well, I can do that, but that's become really hard to read if for each 
> thing they are lots of parameters. 
>
> In fact I event don't how to do that with lots of parameters. Let's say I 
> want do what you say, how can I factorise 
>
>   things:addthing { 'first': 
>     'param1' => 'value1', 
>     .... 
>     'param10' => 'value10', 
>     } 
>
>   things:addthing { 'second': 
>     'param1' => 'value1', 
>     .... 
>     'param10' => 'value10', 
>     } 
>
>   things:addthing { 'third': 
>     'param1' => 'value1', 
>     .... 
>     'param10' => 'value10', 
>     } 
> (actually it's not 10 but 9). 
>
> How can I use a array ? 
>


That's not the case you first presented.  Nevertheless, you can use an 
array title if all the parameters take the same values, in which case it 
simply looks like this:

class my_service { 
  include ::things 
 
  $thinglist = [ 'first', 'second', 'third' ]
  
  things::addthing { $thinglist: 
    param1 => 'value1',
    param2 => 'value2',
    # ...
  } 
}

If each may or does have distinct parameters, then your best bet is to 
externalize them instead of encoding them into your manifests (again: data 
first). There are then multiple ways to feed the parameters to your 
resources, and probably you can externalize the list of resources, too.  
Automated data binding is a powerful and flexible tool, or you can access 
your external data directly, via the `hiera()` family of functions.  There 
are built-in functions that can help with handling the data, and some of 
the functions from the Stdlib module can be really useful here.

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.


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/470ecbfd-79df-460c-92f1-1d8e8879b1b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to