Tim Mooney
2012-Oct-03 21:57 UTC
[Puppet Users] anchor pattern and class containment status
All- We''re currently using puppet 2.7.14 on master and all clients. I thought I understood why ''anchor'' is part of stdlib, but after re-reading both http://projects.puppetlabs.com/projects/puppet/wiki/Anchor_Pattern and http://projects.puppetlabs.com/issues/8040 yesterday in preparation for trying to explain it to one of our team that''s coming up to speed on puppet, now I''m not so certain I really understand. Specifically, is it necessary to use the anchor pattern if your module only defines resources and doesn''t require or include any other classes? For example, if I have class benthic { group { ''squarepants'': ensure => present, gid => ''99999'', } user { ''spongebob'': ensure => present, uid => ''99999'', gid => ''squarepants'', home => ''/home/pineapple'', } package { ''starfish'': ensure => present, } file { ''/etc/starfish.conf'': ensure => file, owner => ''root'', group => ''squarepants'', mode => ''0640'', source => ''puppet:///benthic/starfish.conf'', require => [ Package[''starfish''], User[''spongebob''], ], } service { ''i_m_ready'', ensure => running, enable => true, require => Package[''starfish''], } } Given that class, do I need to use anchors to ensure that the group/user/package/file/service resource graph is correctly attached to (contained within) Class[''benthic''], so that if some other module does someresource { ''whatever'': ... require => Class[''benthic''], } it just works, or, should I augment my class to also have anchor { ''benthic::begin'': } anchor { ''benthic::end'': } Anchor[''benthic::begin''] -> Group[''squarepants''] Service[''i_m_ready''] -> Anchor[''benthic::end''] ? My resources within the class are using explicit "require" when necessary and relying on puppet''s automatic "require" logic in other places so they are correctly ordered, but it''s not clear from the pattern document in the wiki or the ticket whether the issue is solely with nested classes, or whether it''s important to also use the pattern for standard resources. Also, the ticket was with respect to 2.6. I know this hasn''t changed for 2.7, but is there anything in 3.0 that addresses the issue? Tim -- Tim Mooney Tim.Mooney@ndsu.edu Enterprise Computing & Infrastructure 701-231-1076 (Voice) Room 242-J6, IACC Building 701-231-8541 (Fax) North Dakota State University, Fargo, ND 58105-5164 -- 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.
Dan Bode
2012-Oct-03 23:24 UTC
Re: [Puppet Users] anchor pattern and class containment status
On Wed, Oct 3, 2012 at 2:57 PM, Tim Mooney <Tim.Mooney@ndsu.edu> wrote:> > All- > > We''re currently using puppet 2.7.14 on master and all clients. > > I thought I understood why ''anchor'' is part of stdlib, but after > re-reading both > > http://projects.puppetlabs.**com/projects/puppet/wiki/** > Anchor_Pattern<http://projects.puppetlabs.com/projects/puppet/wiki/Anchor_Pattern> > > and > > http://projects.puppetlabs.**com/issues/8040<http://projects.puppetlabs.com/issues/8040> > > yesterday in preparation for trying to explain it to one of our team > that''s coming up to speed on puppet, now I''m not so certain I really > understand. >yep, its probably the most confusing part of Puppet :(> > Specifically, is it necessary to use the anchor pattern if your module > only defines resources and doesn''t require or include any other classes? >you only have to use the anchor pattern when you need to depend on a class that has classes defined in it. The example below does not need the anchor pattern.> For example, if I have > > class benthic { > > group { ''squarepants'': > ensure => present, > gid => ''99999'', > } > > user { ''spongebob'': > ensure => present, > uid => ''99999'', > gid => ''squarepants'', > home => ''/home/pineapple'', > } > > package { ''starfish'': > ensure => present, > } > > file { ''/etc/starfish.conf'': > ensure => file, > owner => ''root'', > group => ''squarepants'', > mode => ''0640'', > source => ''puppet:///benthic/starfish.**conf'', > require => [ > Package[''starfish''], > User[''spongebob''], > ], > } > > service { ''i_m_ready'', > ensure => running, > enable => true, > require => Package[''starfish''], > } > } > > Given that class, do I need to use anchors to ensure that the > group/user/package/file/**service resource graph is correctly attached to > (contained within) Class[''benthic''], so that if some other module does > > someresource { ''whatever'': > ... > require => Class[''benthic''], > } > > it just works, or, should I augment my class to also have > > anchor { ''benthic::begin'': } > anchor { ''benthic::end'': } > > Anchor[''benthic::begin''] -> Group[''squarepants''] > Service[''i_m_ready''] -> Anchor[''benthic::end''] > > ? > > My resources within the class are using explicit "require" when necessary > and relying on puppet''s automatic "require" logic in other places so they > are correctly ordered, but it''s not clear from the pattern document > in the wiki or the ticket whether the issue is solely with nested > classes, or whether it''s important to also use the pattern for standard > resources. > > Also, the ticket was with respect to 2.6. I know this hasn''t changed for > 2.7, but is there anything in 3.0 that addresses the issue? > > Tim > -- > Tim Mooney Tim.Mooney@ndsu.edu > Enterprise Computing & Infrastructure 701-231-1076(Voice) > Room 242-J6, IACC Building 701-231-8541 (Fax) > North Dakota State University, Fargo, ND 58105-5164 > > -- > 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 <puppet-users%2Bunsubscribe@googlegroups.com>. > For more options, visit this group at http://groups.google.com/** > group/puppet-users?hl=en<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.
jcbollinger
2012-Oct-04 13:58 UTC
[Puppet Users] Re: anchor pattern and class containment status
On Wednesday, October 3, 2012 4:59:58 PM UTC-5, Tim Mooney wrote:> > > All- > > We''re currently using puppet 2.7.14 on master and all clients. > > I thought I understood why ''anchor'' is part of stdlib, but after > re-reading both > > > http://projects.puppetlabs.com/projects/puppet/wiki/Anchor_Pattern > > and > > http://projects.puppetlabs.com/issues/8040 > > yesterday in preparation for trying to explain it to one of our team > that''s coming up to speed on puppet, now I''m not so certain I really > understand. > > Specifically, is it necessary to use the anchor pattern if your module > only defines resources and doesn''t require or include any other classes? >No, not as I understand it. The problem is that in Puppet 2.6 and maybe 2.7, classes are not directly represented in the relationship graph. Therefore, if you declare a relationship where one end is a class, it appears in the graph as a collection of relationships with the resources declared by that class. If both ends are classes then you get n x m relationships, where n and m are the numbers of resources declared by the two classes. The need for the anchor pattern arises because the generated relationships to a class Foo''s resources do not include relationships to resources declared by classes declared in the body of Foo, and because declaring a class (except via the ''require'' function) does not create a relationship between the declaring and declared classes. The anchor pattern involves using relationships to resources declared directly by Foo to bound the application order of classes declared by Foo. Anchors are not needed for resources declared directly by Foo (else the anchor pattern wouldn''t work in the first place). The stdlib provides the special ''anchor'' resource type specifically for this purpose, but resources of any other type could be used as well. If Foo does not declare any other classes, then it gains no advantage from the anchor pattern. If the needed ordering of interclass relationships is declared some other way, then the anchor pattern is unneeded. If and when classes gain direct representation in the relationship graph (maybe it''s happened already?), with (optional?) relationships to their included classes, the anchor pattern will no longer be needed. 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/-/ADbfiab83rMJ. 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.
Ryan Coleman
2012-Oct-04 15:37 UTC
Re: [Puppet Users] anchor pattern and class containment status
On Wed, Oct 3, 2012 at 2:57 PM, Tim Mooney <Tim.Mooney@ndsu.edu> wrote:> I thought I understood why ''anchor'' is part of stdlib, but after > re-reading bothI suspect Dan & John have covered this well enough for you but I wanted to point out a nice piece of the Puppet reference manual that covers this. http://docs.puppetlabs.com/puppet/2.7/reference/lang_containment.html#known-issues It explains things better than I ever could. If it''s still not clear enough, please consider filing a ticket against our docs for improvement: https://projects.puppetlabs.com/projects/puppet-docs -- 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.
Tim Mooney
2012-Oct-04 16:45 UTC
Re: [Puppet Users] anchor pattern and class containment status
In regard to: Re: [Puppet Users] anchor pattern and class containment...:> On Wed, Oct 3, 2012 at 2:57 PM, Tim Mooney <Tim.Mooney@ndsu.edu> wrote: > >> >> All- >> >> We''re currently using puppet 2.7.14 on master and all clients. >> >> I thought I understood why ''anchor'' is part of stdlib, but after >> re-reading both >> >> http://projects.puppetlabs.**com/projects/puppet/wiki/** >> Anchor_Pattern<http://projects.puppetlabs.com/projects/puppet/wiki/Anchor_Pattern> >> >> and >> >> http://projects.puppetlabs.**com/issues/8040<http://projects.puppetlabs.com/issues/8040> >> >> yesterday in preparation for trying to explain it to one of our team >> that''s coming up to speed on puppet, now I''m not so certain I really >> understand. >> > > yep, its probably the most confusing part of Puppet :(:-) I think I would vote for create_resources() in that competition.>> Specifically, is it necessary to use the anchor pattern if your module >> only defines resources and doesn''t require or include any other classes? >> > > you only have to use the anchor pattern when you need to depend on a class > that has classes defined in it. The example below does not need the anchor > pattern.Thanks Dan! The info from you & John & Ryan has been very helpful. Tim -- Tim Mooney Tim.Mooney@ndsu.edu Enterprise Computing & Infrastructure 701-231-1076 (Voice) Room 242-J6, IACC Building 701-231-8541 (Fax) North Dakota State University, Fargo, ND 58105-5164 -- 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.
Tim Mooney
2012-Oct-04 18:48 UTC
Re: [Puppet Users] anchor pattern and class containment status
In regard to: Re: [Puppet Users] anchor pattern and class containment...:> On Wed, Oct 3, 2012 at 2:57 PM, Tim Mooney <Tim.Mooney@ndsu.edu> wrote: >> I thought I understood why ''anchor'' is part of stdlib, but after >> re-reading both > > I suspect Dan & John have covered this well enough for you but I > wanted to point out a nice piece of the Puppet reference manual that > covers this. http://docs.puppetlabs.com/puppet/2.7/reference/lang_containment.html#known-issuesThanks Ryan, and thanks especially for the rewritten reference. I haven''t been through all of it yet, but the parts I''ve seen are excellent.> It explains things better than I ever could. If it''s still not clear > enough, please consider filing a ticket against our docs for > improvement: https://projects.puppetlabs.com/projects/puppet-docsI created https://projects.puppetlabs.com/issues/16783 which mentions what I think might be a bug in the second example on that page and also asks for a little clarification. Thanks again for the pointer to the docs! Tim -- Tim Mooney Tim.Mooney@ndsu.edu Enterprise Computing & Infrastructure 701-231-1076 (Voice) Room 242-J6, IACC Building 701-231-8541 (Fax) North Dakota State University, Fargo, ND 58105-5164 -- 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.