Matthias Saou
2013-Apr-18 09:25 UTC
[Puppet Users] Best practice to always fully qualify classes with :: ?
Hi, I''ve been bitten by this quite a few times now, so it got me wondering... When I have both the following classes available : nagios::client mycompany::nagios::client And I decide to "include nagios::client", things get weird. What I''ve seen is that even if it''s from the top scope, puppet can get confused, which in turn gets me confused : From inside the "mycompany" module, I could understand the ambiguity, but from outside it doesn''t make much sense (this is with puppet 3.1.1). Anyway, what does seem to always work is this : include ::nagios::client and of course, this also : class { ''::mycompany::nagios::client'': ... } And given how puppet''s variable scoping works, it makes most sense. But this fully qualified class name syntax isn''t present in the documentation[1][2], so I''m wondering : Is this the proper syntax? Has this (or will this) become the best practice? Matthias [1] http://docs.puppetlabs.com/puppet/2.7/reference/lang_classes.html [2] http://docs.puppetlabs.com/puppet/2.7/reference/lang_scope.html -- Matthias Saou ██ ██ ██ ██ Web: http://matthias.saou.eu/ ██████████████ Mail/XMPP: matthias@saou.eu ████ ██████ ████ ██████████████████████ GPG: 4096R/E755CC63 ██ ██████████████ ██ 8D91 7E2E F048 9C9C 46AF ██ ██ ██ ██ 21A9 7A51 7B82 E755 CC63 ████ ████ -- 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+unsubscribe@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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Ken Coar
2013-Apr-18 19:23 UTC
[Puppet Users] Re: Best practice to always fully qualify classes with :: ?
ARAIK, we haven''t had to do that for anything except parameters from the node manifest, and we haven''t completely finished doing that. Isn''t this covered somewhere in the ''death of dynamic scoping'' discussions/documentation? #k -- 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+unsubscribe@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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Apr-19 14:04 UTC
[Puppet Users] Re: Best practice to always fully qualify classes with :: ?
On Thursday, April 18, 2013 4:25:14 AM UTC-5, Matthias Saou wrote:> > Hi, > > I''ve been bitten by this quite a few times now, so it got me > wondering... > > When I have both the following classes available : > > nagios::client > mycompany::nagios::client > > And I decide to "include nagios::client", things get weird. What I''ve > seen is that even if it''s from the top scope, puppet can get confused, > which in turn gets me confused : From inside the "mycompany" module, I > could understand the ambiguity, but from outside it doesn''t make much > sense (this is with puppet 3.1.1). > > Anyway, what does seem to always work is this : > > include ::nagios::client > > and of course, this also : > > class { ''::mycompany::nagios::client'': ... } > > And given how puppet''s variable scoping works, it makes most sense. But > this fully qualified class name syntax isn''t present in the > documentation[1][2], so I''m wondering : > > Is this the proper syntax? >It is valid syntax.> Has this (or will this) become the best practice? > >Some people do recommend using absolute names everywhere, but I wouldn''t say it''s a consensus best practice. What does seem to be a consensus best practice is to always refer to classes by (at least) their fully-qualified names relative to the top scope (i.e. without the initial "::"). You do need the absolute form under some circumstances, however. In particular, the way name resolution currently works, class name "nagios::client" in your example will be resolved to "::mycompany::nagios::client" everywhere inside module "mycompany" (e.g. inside class mycompany::otherclass, not to mention in mycompany::nagios::client itself). This applies to references to class variables, too, I believe. This is because to resolve a non-absolute name, Puppet starts in the current namespace and checks each containing namespace in turn, from narrowest to broadest, until it finds the target name. There is an outstanding issue (I don''t recall the number) suggesting that Puppet''s name resolution behavior should be changed. One possibility would be to remove relative name resolution altogether, and another would be to skip intermediate namespaces and resolve relative names only against the local namespace and the top namespace. The idea appears to have some traction, but as a backward-incompatible change, I don''t expect it to be implemented before Puppet 4. As for Puppet getting confused, I would be interested in some details -- especially a working example -- if the behavior you observe is not explained by the name resolution behavior I just described. It may be that you have discovered a bug. 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+unsubscribe@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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Apr-19 14:08 UTC
[Puppet Users] Re: Best practice to always fully qualify classes with :: ?
On Thursday, April 18, 2013 4:25:14 AM UTC-5, Matthias Saou wrote:> > > -- > Matthias Saou ██ ██ > ██ ██ > Web: http://matthias.saou.eu/ ██████████████ > Mail/XMPP: matt...@saou.eu <javascript:> ████ ██████ ████ > ██████████████████████ > GPG: 4096R/E755CC63 ██ ██████████████ ██ > 8D91 7E2E F048 9C9C 46AF ██ ██ ██ ██ > 21A9 7A51 7B82 E755 CC63 ████ ████ >By the way, are those redactions in your sig? They look like a Space Invader (http://en.wikipedia.org/wiki/Space_Invaders). :-) 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+unsubscribe@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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Kristof Willaert
2013-Apr-21 11:40 UTC
Re: [Puppet Users] Best practice to always fully qualify classes with :: ?
Hi, [snip] And given how puppet''s variable scoping works, it makes most sense. But> this fully qualified class name syntax isn''t present in the > documentation[1][2], so I''m wondering : > > Is this the proper syntax? > Has this (or will this) become the best practice? >This behaviour, and the (historical) cause for it is described/documented in: docs.puppetlabs.com/puppet/latest/reference/lang_namespaces.html The issue referenced in it, which seeks to improve on this "confusing" behaviour is here: https://projects.puppetlabs.com/issues/2053 Kind regards, k -- 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+unsubscribe@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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Matthias Saou
2013-Apr-22 09:15 UTC
Re: [Puppet Users] Re: Best practice to always fully qualify classes with :: ?
On Fri, 19 Apr 2013 07:08:27 -0700 (PDT) jcbollinger <John.Bollinger@stJude.org> wrote:> By the way, are those redactions in your sig? They look like a Space > Invader (http://en.wikipedia.org/wiki/Space_Invaders). :-)The answer is obvious to anyone using a fixed-width font ;-) Thanks for your reply. Your explanation matches the behaviour I've seen. Matthias -- Matthias Saou ██ ██ ██ ██ Web: http://matthias.saou.eu/ ██████████████ Mail/XMPP: matthias@saou.eu ████ ██████ ████ ██████████████████████ GPG: 4096R/E755CC63 ██ ██████████████ ██ 8D91 7E2E F048 9C9C 46AF ██ ██ ██ ██ 21A9 7A51 7B82 E755 CC63 ████ ████ -- 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+unsubscribe@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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.