Ask Your Question

Are classes declared with "class" automatically contained with the class they reside in?

asked 2017-04-18 11:28:55 -0500

wfsaxton gravatar image

updated 2017-04-18 11:29:30 -0500

I know that using "include" within a class will not contain them (that's what "contain" is for) but I'm using class declarations throughout my containing class does not appear that they are contained. For example, I have 2 classes

class a {
    class { 'a1': }
    class { 'a2': }

class b {
    class { 'b1': }
    class { 'b2': }

I have a class that I want to use these classes in and I want everything inside of them to run in a certain order:

class myclass {
    class { 'a': } ->
    class { 'b': } 

I would expect everything to run like the following (and it was up until a few days ago):

class a1 happens
class a2 happens
class b1 happens
class b2 happens

Now, it seems, I see stuff like this in my puppet runs:

class a1 happens
class b1 happens
class a2 happens
class b2 happens
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-04-18 14:42:33 -0500

DarylW gravatar image

updated 2017-04-18 14:43:45 -0500

I believe you are seeing what I mentioned in the end of my comment to your previous question...

When Should I Care About Class Containment?

Whenever you care about forming ordering relationships against a module that contains subclasses, you likely care about class containment. For example, if you are building an Apache module that you plan to reuse multiple times, and it contains a top level apache class that can be declared directly, as well as several subclasses (think apache::package, apache::file, apache::service, but it can often be much more complex than that). If you want those subclasses to be affected by ordering against the main class, you'll need to deal with class containment

A role containing several profiles, which contain their own sets of resources is the similar class/subclass pattern, and requires the same management using contains or the anchor pattern

It is discussed in this answer to a previous question...

edit flag offensive delete link more


Okay, so the only way to contain a "class" is to use the anchor pattern? You can not use "contains" correct?

wfsaxton gravatar imagewfsaxton ( 2017-04-18 14:52:17 -0500 )edit

One thing that I have done is to declare a class with the resource style, and follow that with a 'contain' call

DarylW gravatar imageDarylW ( 2017-04-19 10:17:47 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-04-18 11:28:55 -0500

Seen: 29 times

Last updated: Apr 18