0

I'm having trouble figuring out how Puppet does inheritence and auto-inclusion of modules.

I have a Puppet class that works as expect when I test it "locally" but fails when I push it to my nodes via the Puppet server.

"Locally" means running via puppet apply and sending in the correct local module path.

Here is an example of the classes and what happens. I've tried to strip this down to the least number of things that produce this problem, however I admit I'm not positive that I could be omitting something important.

What I'm trying to achieve is writing new components for an existing module without breaking backward compatibility to nodes that already include the old module. I'm migrating a poorly written module to a be more appropriately written, and I want to push it out in stages without breaking existing installations.

My node declaration is as follows:

node /myserver.*/ {
    include myclass::server
}

The manifests are declared as follows:

# File "myclass/manifests/init.pp"
class myclass {

    file { '/etc/oldconfig.conf':
        ensure => file,
        owner  => root,
        group  => root,
        mode   => '0644',
        source => 'puppet:///files/oldconfig.conf',
    }

}

# File "myclass/manifests/server.pp"
class myclass::server {
    include myclass::next
}

# File "myclass/manifests/next.pp"
class myclass::next {

    # Remove clutter
    file { '/etc/oldconfig.conf':
        ensure => absent
    }

    ... more stuff, not relevant ...
}

To sum up, the original init.pp includes a file, "oldconfig.conf". The new module class, "next", deletes this file.

When I run the module using "puppet apply", (i.e. locally), I do not get any conflicts and the run ends with a zero exit status.

But when I run puppet agent -t on the real node, which is pulling the manifests from the puppet server, I get the following:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: File[/etc/oldconfig.conf] is already declared in file /etc/puppet/environments/common/myclass/manifests/init.pp:48; cannot redeclare at /etc/puppet/environments/common/myclass/manifests/next.pp:4 on node mynode01.example.com

Is there some sort of Puppet manifest inheritance and/or auto-include that happens on runs from the puppetmaster that differ from local puppet apply runs?

If I include just a sub-class -- e.g. include myclass::my_subclass -- in a Puppet manifest's node declaration, should I expect that the subclass is always going to reference the parent class? I don't recall seeing this behavior before this example, and I also couldn't find explicit documentation answering this question. (It's kinda hard to Google for this though)

1 Answer 1

1

I'm having trouble figuring out how Puppet does inheritence and auto-inclusion of modules.

There is no inheritance, subclasses or parent classes in your example, I don't think it's that. The naming is separate to inheritance, it shouldn't imply that the parent class is included in the catalog.

Is there some sort of Puppet manifest inheritance and/or auto-include that happens on runs from the puppetmaster that differ from local puppet apply runs?

  1. Site manifests may be on your Puppet master that are not used in your local apply run. These may include the class directly, or indirectly via hiera_include or similar. Check any site manifests and usage of hiera_include and your data files if applicable.
  2. External node classifiers may be configured on a master with a list of classes to include on the node.

Try adding debug to the myclass class to show where it's being included from:

notice("myclass included by $caller_module_name")

(https://docs.puppet.com/puppet/latest/reference/lang_facts_and_builtin_vars.html#compiler-variables)

This may not show anything if included from an ENC.

1
  • I actually found the problem. It was definitely "Site manifests may be on your Puppet master that are not used in your local apply run" -- there is a "stage => first" stanza in my main site.pp that is not present in my testing local.pp. And of course, that stanza includes the module I'm refactoring.
    – JDS
    Oct 4, 2016 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .