On Wednesday, November 28, 2012 10:09:10 AM UTC-6, Smashed
wrote:>
> I''m pretty sure I ran into the infamous containment issue (
> http://projects.puppetlabs.com/issues/8040) I have some questions
> regarding this issue as well as the proposed work-around… anchors.
>
> First off if all of the classes you are trying to contained are owned by
> you could you not just use require instead of include? For example:
>
> class foo {
> resouce { ''name'':
> require => Class["bar"]
> }
> }
>
> class bar {
> include a
> include b
> include c
> }
>
> The above snipped will cause a problem if the resource in Foo depends on
> a,b and c being completed. Couldn''t you just do this instead?
>
> class bar {
> require a
> require b
> require c
> }
>
Yes, you can do that and it should work for your scenario. It is not
equivalent to applying the anchor pattern, however. In particular, it is
no help at all when you use "before =>
Class[''bar'']", whereas the anchor
pattern works for that case, too.
>
> I believe the above would work, but then again this is only if you
"own"
> the classes you are trying to include.. i.e., this won''t work with
external
> modules that were downloaded from puppet forge. So, other than the use case
> when you are trying to create a dependency on classes/modules you
don''t
> own, you could just use require instead of anchors. Is this correct?
>
Either way, you need to own class Bar (because you''re creating /
modifying
it), but you do not *need* to own classes ''a'',
''b'', and ''c'' for the pattern
to work. It is risky to attempt to contain classes you do not own,
however, because you can easily introduce cyclic resource relationships
that way.
>
> Ok now for my question on anchors. Well its more of a request then a
> question. Could someone please post a simplified version of the work around
> using anchors for the above situation? I tried to read though the wiki but
> I didn''t fully grasp how anchors worked. Didn''t help that
someone told me
> in the IRC room that the example on the wiki has a bug in it.
>
>
Anchors make use of the fact that relationships with classes are
effectively propagated to their resources (such as anchor resources), even
though they are not propagated to referenced classes. There is nothing
special about the anchor resource type that makes the pattern work; the
same can be done with any other resource, and where there is another
resource that fills that role naturally it is better to use that. Anchors
serve principally to clarify, as they have no other purpose than to
participate in ordering relationships.
Here is how your example might look with anchors:
class bar {
include a
include b
include c
anchor { ''bar_start'':
before => [ Class[''a''], Class[''b''],
Class[''c''] ]
}
anchor { ''bar_end'':
require => [ Class[''a''], Class[''b''],
Class[''c''] ]
}
}
If there were ordering relationships among classes ''a'',
''b'', and ''c'', then
the anchors'' ''before'' and ''require''
parameters could be simpler. Also, you
can write the relationships in other ways, such as using the chain
operators, but it all amounts to the same thing as long as you set up the
same relationships.
The point is that anything that has a ''before'' relationship
with
Class[''bar''], thereby has a ''before''
relationship with Anchor[''bar_start'']
(and Anchor[''bar_end'']), and
Anchor[''bar_start'']''s ''before''
relationship
with the contained classes ensures that it is applied before the resources
belonging to those classes. Similarly for ''require''
relationships and
Anchor[''bar_end''].
Note well that you should apply that pattern only where the nature of class
bar calls for it. In many cases, there is no particular need for
containment or even relative ordering of the classes declared by a given
class.
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/-/di1U2ZXmphUJ.
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.