On Thursday, June 11, 2015 at 3:23:55 PM UTC-5, Albert Shih wrote:
>
> Hi, 
>
> Let's say I have a module to manage something on a server so 
>
>   modules/things/manifests/init.pp 
>   ......................../addthing.pp 
>
> the addthing.pp whould be a define. 
>
> And I use this « addthing » inside other module, how can I get the list of 
> all thing I add. For example 
>
>   class my_service { 
>
>     include ::things 
>
>     things::addthing { 'first' } 
>     things::addthing { 'second' } 
>     things::addthing { 'third' } 
>
>     # and now I want inside $my_things a string like 'first, second, 
> third' 
>
>     } 
>
>

You don't.  If you were willing to write a custom function or possibly to 
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.

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 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.


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/21e547dd-e02f-4b36-8a8f-da975b3846fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to