Hi,
require => is largely orthogonal to the other mentioned concepts. Do
require whatever must be handled first by puppet, e.g.
service { "ntp": require => Package["ntp"] }
so that puppet doesn't try and start a service before its package is
even installed. It will *not* automagically install package ntp, you
need to give puppet an actual resource, i.e. package { "ntp": ... }.
The same goes for classes: Requiring a Class[...] is god practice, but
you must include it explicitly. An unincluded class cannot be required
(or before'd, notified etc.)
As for include vs. inherit - a good rule of thumb is *always* to include.
Use inherit only for situations like this:
class ntp::service {
service { "ntp": enable => true }
}
class ntp::service::watchdog inherits ntp::service {
Service { "ntp": ensure => "running" }
}
So selected nodes can include the inheriting class to override specific
parameters of class ntp::service's resources.
Inheritance is a good way to do this and it should not be used for
anything else.
HTH,
Felix
On 01/18/2012 11:32 AM, Antidot SAS wrote:
> Hi everyone,
>
>
> I am just rediting an old post because don't see any answer regarding
> this matter:
>
>
>
> ---------- Forwarded message ----------
> From: Arnau Bria <[email protected] <mailto:[email protected]>>
> Date: Jun 30 2009, 5:01 pm
> Subject: import Class vs require vs inherits
> To: Puppet Users
>
>
> Hi all,
>
> I have a couple of "basic" questions on classes.
>
> In a class, what's the diff between:
>
> *don't take in count syntax, please.
>
> ----------------------------------
>
> class class_B {
>
> package { fortune }
>
> file { dummy }
>
> }
>
> ----------------------------------
>
> example 1)
>
> class class_A {
>
> include class_B
> package { foo }
>
> }
>
>
> example 2)
>
> class class_A {
>
> file { bogus
>
> before = > Package [foo],
>
> }
> package { foo
>
> require =>Class["class_B"],
>
> }
>
> }
>
>
> example 3)
>
> class class_A inherits class_B {
>
> package { foo }
>
> }
>
> In first example class_B will be evaluated before ALL class_A.
> so package fortune and dummy file will be installed/created before
> package foo.
>
> In second one, class_B will be evaluted ONLY when package
> foo. So, first bogus package, then, before foo, fortune and summy file.
>
> And on third example? same as first one?
>
> I don't see difference between example 1 and 3.
> -------------
>
>
> Does anyone could explain to me thoses differences?
>
> Regards,
> JM
>
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.