Are these the same?

60 views
Skip to first unread message

Mark

unread,
Nov 25, 2012, 11:56:27 AM11/25/12
to puppet...@googlegroups.com
Trying to figure out if these would behave the same or not?

Example 1:
-----------------

class Foo {
require Bar
someresource { 'baz':
…. # This depends on A,B and C being already completed
}
}

class Bar {
include A
include B
include C
}


Example 2:
----------------

class Foo {
include Bar
someresource { 'baz':
….
require => Class['Bar']
}
}

class Bar {
include A
include B
include C
}


So will these behave the same? When I require Bar in the first example are the A,B and C resources guaranteed to be executed before the resource in Foo? Same question goes for example 2


Thanks for the clarification!

Ugo Bellavance

unread,
Nov 25, 2012, 2:37:47 PM11/25/12
to puppet...@googlegroups.com
I'm not a puppet expert, but your situation would probably fit more with an usage of stages.

It would allow you to define stages and order or those.

Mark

unread,
Nov 25, 2012, 3:26:26 PM11/25/12
to puppet...@googlegroups.com, puppet...@googlegroups.com
Stages? Would you mind elaborating?

Sent from my iPhone
--
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/-/oP6xEACJKIwJ.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Ugo Bellavance

unread,
Nov 25, 2012, 4:05:40 PM11/25/12
to puppet...@googlegroups.com
I read about that in the puppet 2.7 cookbook book that I bought a few days ago.

Ugo Bellavance

unread,
Nov 25, 2012, 4:10:09 PM11/25/12
to puppet...@googlegroups.com

Nan Liu

unread,
Nov 26, 2012, 1:31:07 PM11/26/12
to puppet...@googlegroups.com
They don't work as expected. You need containment resources in class Bar. See documentation and ticket 8040 for more info and work around:


HTH,

Nan

jcbollinger

unread,
Nov 26, 2012, 1:59:12 PM11/26/12
to puppet...@googlegroups.com


On Sunday, November 25, 2012 10:56:40 AM UTC-6, Smashed wrote:
Trying to figure out if these would behave the same or not?

Example 1:
-----------------

class Foo {
  require Bar
  someresource { 'baz':
        …. # This depends on A,B and C being already completed
  }
}

class Bar {
  include A
  include B
  include C
}


Example 2:
----------------

class Foo {
  include Bar
  someresource { 'baz':
     ….
     require => Class['Bar']
  }
}

class Bar {
  include A
  include B
  include C
}


So will these behave the same?


Yes.

 
When I require Bar in the first example are the A,B and C resources guaranteed to be executed before the resource in Foo?


A, B, and C are classes, not resources.  The resources they contain are not guaranteed to be applied before Someresource['baz'], but if there were any resources declared directly by class Bar then they would all be applied before Someresource['baz'].

Do not use run stages for this.  They are way overkill for the problem.  If you needed to add new stages every time you had to enforce resource ordering then you would quickly end up with an unmanageable mess.

See my response to your other thread on this question (https://groups.google.com/forum/?fromgroups=#!topic/puppet-users/buREmDC8Py4) for more information.  In the future, it will suffice to ask your question once.


John

Jakov Sosic

unread,
Nov 30, 2012, 3:01:37 PM11/30/12
to puppet...@googlegroups.com
On 11/26/2012 07:59 PM, jcbollinger wrote:

> Trying to figure out if these would behave the same or not?
>
> Example 1:
> -----------------
>
> class Foo {
> require Bar
>
> Example 2:
> ----------------
>
> class Foo {
> include Bar

>
> So will these behave the same?
>
> Yes.


So include and require do pretty much the same?


Johan De Wit

unread,
Nov 30, 2012, 5:48:10 PM11/30/12
to puppet...@googlegroups.com, Jakov Sosic
http://docs.puppetlabs.com/references/stable/function.html#include and
http://docs.puppetlabs.com/references/stable/function.html#require

Thy both includes the class, but require adds a dependency to the
included class.
from the docs :
This function is a superset of the �include� function, adding a class
relationship so that the requiring class depends on the required class.
Grts

Johan

--
Johan De Wit

Open Source Consultant
Red Hat Certified Engineer (805008667232363)
Puppet Certified Professional 2013 (PCP0000006)
_________________________________________________________

Open-Future Phone +32 (0)2/255 70 70
Zavelstraat 72 Fax +32 (0)2/255 70 71
3071 KORTENBERG Mobile +32 (0)474/42 40 73
BELGIUM http://www.open-future.be
_________________________________________________________

Jakov Sosic

unread,
Nov 30, 2012, 6:25:42 PM11/30/12
to puppet...@googlegroups.com
On 11/30/2012 11:48 PM, Johan De Wit wrote:

> Thy both includes the class, but require adds a dependency to the
> included class.
> from the docs :
> This function is a superset of the �include� function, adding a class
> relationship so that the requiring class depends on the required class.
> Grts

What I was interested in is: Does the 'require' enforce order of
execution, so that the required class will be applied before the class
that requires it?

Henrik Lindberg

unread,
Dec 2, 2012, 12:42:36 PM12/2/12
to puppet...@googlegroups.com
Yes.
require is basically shorthand for

class a {
include x
Class['x'] -> Class['a'] # x before a
}

If the require function makes things difficult, you can manage the
relationship using the ->, <-, <~, ~> operators, or as meta-parameters
in resources (i.e. require => Class['x']).

You can also look at Stages if you like to separate the concerns (some
classes should be after some other classes, but you do not want to
record the exact classes as you may want to change them).
You can create additional stages (there is a main stage by default), and
assign classes to stages.

See more here: http://docs.puppetlabs.com/guides/language_guide.html -
"Run Stages".

Hope that helps.
- henrik



Reply all
Reply to author
Forward
0 new messages