As usual, I''m confused about scope in puppet. This puppet 2.7.1. In my classes below, the bottom class, company::web::content, requires the file resource ''/usr/local/company''. However, that resource is defined two includes back in the class company::common. I always thought this wasn''t supposed to work, and that you could only access the immediate scope, not the scope of stuff beyond this. It does work however. Is it supposed to. Why? class company::common { file { ''/usr/local/company'': .... } } class company::web::common { include company::common } class company::web::content { include company::web::common file { ''/usr/local/company/www'': require => File[''/usr/local/company''] } } Doug. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Tue, Aug 07, 2012 at 11:25:32AM -0700, Douglas Garstang wrote:> As usual, I''m confused about scope in puppet. This puppet 2.7.1. > > In my classes below, the bottom class, company::web::content, requires > the file resource ''/usr/local/company''. However, that resource is > defined two includes back in the class company::common. I always > thought this wasn''t supposed to work, and that you could only access > the immediate scope, not the scope of stuff beyond this. It does work > however. Is it supposed to. Why?Without having dug into it, I think scope applies more for variables. Resources can be related to other resources no matter where they are. Below you''ve just defined the equivalent of: class superme { file { ''/tmp/file1'': content => "123\n", } file { ''/tmp/file2'': content => "456\n", require => File[''/tmp/file1''], } } For what it''s worth, I think it''s supposed to work how you''ve described below.> class company::common { > file { > ''/usr/local/company'': > .... > } > } > > > class company::web::common { > include company::common > } > > > class company::web::content { > include company::web::common > > file { > ''/usr/local/company/www'': > require => File[''/usr/local/company''] > } > } > > Doug. > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Tuesday, August 7, 2012 1:25:32 PM UTC-5, Douglas wrote:> > As usual, I''m confused about scope in puppet. This puppet 2.7.1. > > In my classes below, the bottom class, company::web::content, requires > the file resource ''/usr/local/company''. However, that resource is > defined two includes back in the class company::common. I always > thought this wasn''t supposed to work, and that you could only access > the immediate scope, not the scope of stuff beyond this. It does work > however. Is it supposed to. Why? >Yes, it is supposed to. All classes and resources have global scope once they are declared. The ''include'' function does not introduce classes and their resources into the current, innermost scope -- it doesn''t need to do so, and couldn''t even if it wanted to do. Instead, ''include'' ensures that the specified class has been parsed and added to the catalog, which, as I said, puts them into the global scope. The model pretty much has to work that way, because the physical resources of the target node all have global scope, too. It is useful and appropriate for classes and definitions to ''include'' (or ''require'') the classes on which they rely, provided that those classes are not parametrized (Puppet <= 2.7.x). Aside from it''s plain aggregation function, that way it''s a lot easier to make classes independent of the order in which they are declared, plus it has documentary value. Classes that ''include'' all the classes on which they directly rely are more robust. However, there is no requirement for a class to ''include'' its dependencies. If a class does not do so, then it simply relies on those dependencies to have been declared by some other class that was parsed before it. Users of parametrized classes rely heavily on this, because parametrized classes can be declared only once, but they may need to be referenced by many other classes. John> > > class company::common { > file { > ''/usr/local/company'': > .... > } > } > > > class company::web::common { > include company::common > } > > > class company::web::content { > include company::web::common > > file { > ''/usr/local/company/www'': > require => File[''/usr/local/company''] > } > } > > Doug. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/2i9JGMwdfdAJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Wed, Aug 8, 2012 at 6:25 AM, jcbollinger <John.Bollinger@stjude.org> wrote:> > > On Tuesday, August 7, 2012 1:25:32 PM UTC-5, Douglas wrote: >> >> As usual, I''m confused about scope in puppet. This puppet 2.7.1. >> >> In my classes below, the bottom class, company::web::content, requires >> the file resource ''/usr/local/company''. However, that resource is >> defined two includes back in the class company::common. I always >> thought this wasn''t supposed to work, and that you could only access >> the immediate scope, not the scope of stuff beyond this. It does work >> however. Is it supposed to. Why? > > > Yes, it is supposed to. All classes and resources have global scope once > they are declared. The ''include'' function does not introduce classes and > their resources into the current, innermost scope -- it doesn''t need to do > so, and couldn''t even if it wanted to do. Instead, ''include'' ensures that > the specified class has been parsed and added to the catalog, which, as I > said, puts them into the global scope. > > The model pretty much has to work that way, because the physical resources > of the target node all have global scope, too. > > It is useful and appropriate for classes and definitions to ''include'' (or > ''require'') the classes on which they rely, provided that those classes are > not parametrized (Puppet <= 2.7.x). Aside from it''s plain aggregation > function, that way it''s a lot easier to make classes independent of the > order in which they are declared, plus it has documentary value. Classes > that ''include'' all the classes on which they directly rely are more robust. > > However, there is no requirement for a class to ''include'' its dependencies. > If a class does not do so, then it simply relies on those dependencies to > have been declared by some other class that was parsed before it. Users of > parametrized classes rely heavily on this, because parametrized classes can > be declared only once, but they may need to be referenced by many other > classes. >Ok, so to put it another way, your saying that once a class is included, it''s scope becomes global and can be used anywhere else, no matter the relationship between the class where it was included, and the class that''s trying to access it? Doug. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Wednesday, August 8, 2012 4:58:37 PM UTC-5, Douglas wrote:> Ok, so to put it another way, your saying that once a class is > included, it''s scope becomes global and can be used anywhere else, no > matter the relationship between the class where it was included, and > the class that''s trying to access it? >Yes. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/oTVNJNl4SPEJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.