sorry for jumping to conclusions, but your questions suggest that you're
committed to some rather horribly design ideas.
Can you add some meat to your inquiry? What are your trying to achieve?
Under most circumstances, you don't want inheritance at all.
Use it *only* to override the parameters of one or more resources in the
base class.
HTH,
Felix
On 02/07/2012 01:56 PM, jimbob palmer wrote:
>> sorry for jumping to conclusions, but your questions suggest that you're
>> > committed to some rather horribly design ideas.
> Then please educate me! What's horrible about it?
There are few use cases for parameterized classes, and also few for
inheritance. Combining them could be considered an advanced concept.
There is nothing here that suggests you need either technique.
No offense, I just want to keep people (you) from shooting yourselves in
the feet.
>> >
>> > Can you add some meat to your inquiry? What are your trying to achieve?
> I have a class which represents a group of yum repositories
> (something::blah) and that class calls each repository
> (something::aaa)
>
You probably want to create a custom type like
define my_yum_repo($url) {
yum_repo { $name: ...
}
Then you can use it like this:
class something {
my_yum_repo {
"internal_repo1": url => "http://...";
"internal_repo2": ... ;
}
}
Sorry if doesn't hit the spot, your problem description is still rather
abstract.
HTH,
Felix
So can I be sure that the include will run first, before the "specific
stuff" here?
>
>
> instead of this:
>
> # DONT DO THIS
> class foo::specific inherits 'foo::common' {
> }
Okay. So if I am not meant to use class inheritance for this, when
should I use it?
Is scoping different between include and inherits?
Kind of, but you need to change your thinking. The include does not
_run_ before the specific stuff, it _declares_ foo::common. The result
is not a sequential run of something, but a graph - a catalog of
resources and relationships :)
> Okay. So if I am not meant to use class inheritance for this, when
> should I use it?
Hm, I'm tempted to say "never" but this is an example use
http://docs.puppetlabs.com/guides/parameterized_classes.html#appendix-smart-parameter-defaults
Yikes so how can I be sure that the included stuff gets included
before I need it? Say it pulls in some variables and package
requirements.
And a related question: if I have a case statement at the top of my
class that sets a variable, how can I be sure the variable will be set
before I need it lower down in the same class?
>
>
>> Okay. So if I am not meant to use class inheritance for this, when
>> should I use it?
>
>
> Hm, I'm tempted to say "never" but this is an example use
>
> http://docs.puppetlabs.com/guides/parameterized_classes.html#appendix-smart-parameter-defaults
>
>
> --
> http://www.uib.no/personer/Jan.Ivar.Beddari
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> 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.
>
Yes, you just have to be explicit and specify relationship.
> Yikes so how can I be sure that the included stuff gets included
> before I need it? Say it pulls in some variables and package
> requirements.
The variables are evaluated during compilation so include the class
before you reference any variables. If you need resource in
foo::package applied before foo::specific:
require 'foo::package'
or 2.7 parametrized class:
class { 'foo::package':
version => 'latest',
}
Class['foo::package'] -> Class['foo::specific']
> And a related question: if I have a case statement at the top of my
> class that sets a variable, how can I be sure the variable will be set
> before I need it lower down in the same class?
If you mean there's a variable in foo::common you want to reference in
foo::specific just use fully qualified variable and include
foo::common.
include foo::common
if $::foo::common:variable {
...
}
HTH,
Nan
> 2012/2/7 Jan Ivar Beddari <jan.ivar...@uib.no>:
>> On 02/07/2012 03:54 PM, jimbob palmer wrote:
>>>>
>>>>
>>>> # The right way
>>>> class foo::specific {
>>>> include 'foo::common'
>>>> # specific stuff
>>>> }
>>>
>>>
>>> So can I be sure that the include will run first, before the "specific
>>> stuff" here?
>>
>>
>> Kind of, but you need to change your thinking. The include does not _run_
>> before the specific stuff, it _declares_ foo::common. The result is not a
>> sequential run of something, but a graph - a catalog of resources and
>> relationships :)
>
> Yikes so how can I be sure that the included stuff gets included
> before I need it? Say it pulls in some variables and package
> requirements.
----
require [ Class["some_class"], Package["some_package"] ]
----
> And a related question: if I have a case statement at the top of my
> class that sets a variable, how can I be sure the variable will be set
> before I need it lower down in the same class?
----
leap of faith
Craig
Thanks. but I meant more within the same class: before I was using
class inheritance to ensure that I don't have to worry about ordering.
Now I will use includes as you suggest. Say I have a class that has an
include, is there a guarantee that the include will always be included
before the rest of the class is examined?
>> And a related question: if I have a case statement at the top of my
>> class that sets a variable, how can I be sure the variable will be set
>> before I need it lower down in the same class?
>
> If you mean there's a variable in foo::common you want to reference in
> foo::specific just use fully qualified variable and include
> foo::common.
I mean withint the same class. Say I have a case statement at the top
of my class that sets a variable, will that run before I need the
variable (later in the same class)?
Sorry for the confusion.
On 02/08/2012 07:43 AM, jimbob palmer wrote:
> Now I will use includes as you suggest. Say I have a class that has an
> include, is there a guarantee that the include will always be included
> before the rest of the class is examined?
Referencing variables scoped to included classes will *always* work.
include foo
notify { "$foo::bar": }
where $bar is declared in the class foo.
Don't even thing about using $bar (without explicit scope $foo::bar)
anywhere outside the very foo class.
There are dynamic scoping features, but using them is stronly
discouraged (by me at least ;-)
> I mean withint the same class. Say I have a case statement at the top
> of my class that sets a variable, will that run before I need the
> variable (later in the same class)?
Yes, this most definitely works.
I don't even think it's important in which order you use and declare
variables, because variables can be assigned only once. So there is no
concept of "earlier" or "later" where variables are concerned.
HTH,
Felix
So say I have a single class which in order I need to ensure a file
doesn't exist, then after that install a package, then after that call
a define function.
The file package part is doable with a chain (although I could be more
confident about where they are defined), but how do I put the define
function in the chain?
>
> HTH,
> Felix
On 02/08/2012 02:57 PM, jimbob palmer wrote:
> So say I have a single class which in order I need to ensure a file
> doesn't exist, then after that install a package, then after that call
> a define function.
careful: define() has nothing to do with custom functions.
You create a definded *type*. You do not call a define, you create
instances, resource-like entities that comprise multiple resources each.
> The file package part is doable with a chain (although I could be more
Absolutelzy.
> confident about where they are defined), but how do I put the define
> function in the chain?
Suppose your defined type is define mycooltype() { }.
package { "whatever": before => Mycooltype["cool-type-entity"] }
If your question was geared to the effect of "i want my custom type to
be defined after the package was ensured", well, that doesn't make
sense. Chains and require/before are used to control the order of agent
operation. That's all you need to worry about. At what time the *master*
processes your define() is not important at all.
Caveat:
mycooltype { "cool-type-entity": require => Package["whatever"] }
will *not* work out of the box. See defined types in
http://docs.puppetlabs.com/guides/language_guide.html#resource-collections
for details.
HTH,
Felix