On Tuesday, September 25, 2012 4:05:26 AM UTC-5, Nikita Burtsev wrote:
>
> Hello,
>
> We have a weird problem with includes:
> err: Could not retrieve catalog from remote server: Error 400 on SERVER:
> Could not find resource 'Class[Common_software]' for relationship from
> 'Class[Default_repositories]'
>
> My wild guess would be that "common_software" gets in before
> "default_repositories" and thus the error message. If i run agent again it
> sometimes goes away and configuration gets applied, sometimes it does not.
> I even tried using stages, did not help.
>
> nodes.pp looks like this;
>
> stage { pre: before => Stage[main] }
>
> node 'basenode' {
>
> class { 'default_repositories' : stage => pre }
> <some stuff here>
> include common_software-site
> <some more stuff here>
> }
>
> We have multiple (read: many) sites with configuration which varies here
> and there. To make things a bit more sane and to reduce duplication we
> decided to have common code base we ship to each site which then changes
> from site to site using inheritance mechanism, so, for example, there is
> class called "common_software" which defines some resources and then there
> is "common_software-site" which inherits base class and adds some
> functionality.
>
> If I include child class in nodes.pp problem is there, but including
> parent class fixes the problem.
>
> Any thoughts on the matter?
>
>
Yes:
1. You really should arrange your classes in modules.
2. Class names must not contain hyphens (-). They work accidentally in
some versions of Puppet, but they do not work in others. I doubt that's
the source of your present problem, but it will likely cause you trouble in
the future.
3. Although it has its use cases, class inheritance is usually *not* the
best choice in Puppet. If you're not using it to override parameters
declared in a superclass, or to force parsing of the superclass to make it
safe for a parametrized class to use the superclass's variables as
parameter defaults, then you are misusing it. You almost always want
composition instead of inheritance (i.e. "include foo" in the body instead
of "inherits foo" in the header).
4. It is safe to explicitly include a superclass and its subclass on the
same node, in any order.
5. It is safe to 'include' a non-parametrized class any number of times.
6. Puppet parses any given manifest from top to bottom. In particular,
given your node declaration, it will parse the declaration of class
'default_repositories' before anything else in the node declaration. In
particular, it will parse that declaration before it parses "include
common_software-site"
7. Puppet parses a class's definition immediately the first time it
encounters a declaration of that class. In your case, that means it will
always start parsing the definition of class 'default_repositories' before
the definition of class 'common_software-site'. If it has no other reason
to parse class 'common_software' than class 'common_software-site'
inheriting from it, then it will (attempt to) parse all of the definition
of 'default_repositories' before it parses either of the others.
8. The appearance of a reference to a class is not a reason to parse
that class.
9. Therefore, if class 'default_repositories' contains a reference to
Class['common_software'] but does nothing to ensure that it has been parsed
(for example, "include 'common_software'") then I would expect exactly the
error you describe.
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/-/oTOpKAuYlvkJ.
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.