On Monday, September 9, 2013 6:13:46 PM UTC-5, sjr wrote:
>
> Hi,
>
> I've been doing some tests with some internal methods just to mess a 
> little and learn a bit about puppet internals but found myself in a 
> situation which I don't really understand and I was hoping someone around 
> could help me to get it.
>
> I have a test module with the following init.pp:
>
> class test1 
> {                                                                             
>                                                                               
>                        
>
>   file 
> {'/tmp/test1':                                                                
>                                                                               
>                             
>
>     content => 
> template('test1/test1.erb'),                                                  
>                                                                               
>                     
>
>   
> }                                                                             
>                                                                               
>                                  
>
>                                                                               
>                                                                               
>                                    
>
>   Test1::Print <| |> -> 
> File['/tmp/test1']                                                            
>                                                                               
>            
>
> }
>
> The define test1::print looks like:
>
> define test1::print 
> (                                                                             
>                                                                               
>                
>
>   
> $message                                                                      
>                                                                               
>                                  
>
> ) 
> {                                                                             
>                                                                               
>                                  
>
>   notify{$message: 
> }                                                                             
>                                                                               
>                 
>
> }
>
> So nothing really special, then in the template I try to catch all the 
> resources in the catalog with "scope.catalog.resources" method, nothing I 
> came up with by myself I saw it in a module and thought it was a neat trick 
> and wanted to try it and learn what else I could do with this kind of stuff.
>
> The problem I'm having is that the template seems to be "compiled" before 
> all the resources are in the catalog as the file only contains the 
> following list of resources:
>
> Stage[main]
> Class[Settings]
> Class[main]
> Node[default]
> Class[Test1]
>
> In puppet's output, the relationships seem to be well defined but feels 
> like puppet is somehow applying (catching?) the template even before 
> creating the actual file.
>
> The template has the following content:
>
> <% @test = scope.catalog.resources.select { |r| r.type } -%>
> <% @test.each do |t| -%>
> <%= t %>
> <% end %>
>
> Am I missing anything? I expected to see in the file the defined type 
> test1::print...
>
>
You are missing several things, including at least

   1. Puppet relationships, such as are declared via the arrow operators or 
   'require' and 'before' metaparameters, influence only the order in which 
   resources are applied by the agent.  They have no bearing on the order of 
   events during catalog compilation.
   2. Defined types are *types*, not resources.  They are thoroughly 
   analogous to native resource types such as File.  You could see *
   instances* of defined types among your catalog resources if you declared 
   any (you didn't), but you will not see the defined types themselves.
   3. scope.catalog.resources is an awful hack, not a "neat trick", because 
   it is sensitive to when during the compilation process the template is 
   evaluated.  To build robust and reliable classes and modules you must avoid 
   depending on mechanisms that are sensitive to evaluation order (sometimes 
   inaccurately called "parse order", including by me).


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 puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to