Duplicate declaration of same resource defined in separate classes

If you control both modules, you should write a third class (module) to manage the shared resource.

class build_essential {
    package { 'build-essential': ensure => installed }
}

Contexts that require the package just

include build_essential

Do not touch the defined() function with a 12" pole. There can be only pain down this road.


This is common question when dealing with multiple modules.

There's a number of ways of doing this, the best practise is to modularise and allow the installation of build essential as a parameter:

class icu ($manage_buildessential = false){

  if ($manage_buildessential == true) {
   package { "build-essential": 
     ensure => installed
   }
 }
}

Then, where you want to include your ICU class:

class {'icu':
   manage_buildessential => 'false',
}

However, for a quick and dirty fix:

if ! defined(Package['build-essential']) {
    package { 'build-essential': ensure => installed }
}

Or if you have puppetlabs-stdlib module:

ensure_packages('build-essential')

Tags:

Puppet