Different puppet modules with one common resource

I am writing particular modules for the different roles of my servers. So I have a puppet and a puppet-dashboard-Module. The puppet module ensures that puppet is correct installed. The puppet-dashboard does the same for the puppet-dashboard, off course.

Both modules need the puppetlabs apt source (btw. I am using https://github.com/puppetlabs/puppet-apt). So I have the following defined resource in puppet and puppet-dashboard-module:

    apt::source { "puppetlabs":
      location          => "http://apt.puppetlabs.com",
      release           => "squeeze",
      repos             => "main",
      required_packages => true,
      include_src       => false,
      key               => "4BD6EC30",
      key_server        => "pgp.mit.edu",
    }

Now I get the following error on my agent:

err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Apt::Source[puppetlabs] is already declared in file /etc/puppet/modules/puppet/manifests/base.pp at line 27; cannot redeclare at /etc/puppet/modules/puppet-dashboard/manifests/init.pp:42 on node server123

The particular modules are independently of each other. Therefore I think it is correct to set the dependency of this apt source separately in each module.

A workaround would be to rename one source from puppetlabs to puppetlabs2 or sth. like that. But there must be another solution.

I am curious about your responses!


Whenever I have this problem (particularly common with packages), I just put the resource in a class, all by itself:

class git {
    package { 'git': ensure => installed, }
}

Then I include the class instead of defining the resource.

Next problem: but they are used by different modules! Yes, either put them in common, or in some other module-specific common module (say, puppet-common).


There are several ways to address this. I'd personally split your apt source into a separate class and then use an include or inheritance (depending on situation) to pull this class into where ever you need it.