Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Resource declaration with puppet and puppet::master #78

Open
cloudsurf-digital opened this issue Feb 4, 2016 · 9 comments
Open

Comments

@cloudsurf-digital
Copy link

Hi,

from me pespective it seems to be a very strange phenomenon, i'd search for another declare of Class[Puppet] but didnt find it. also the error message is strange:

init.pp:6:3

???

2016-02-04 10:20:47,603 ERROR [qtp1208500937-60] [puppet-server] Puppet Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Class[Puppet] is already declared; cannot red
eclare at /data/puppet/code/environments/PuppetMasterFix/modules/profile_puppetagent_cron/manifests/init.pp:6 at /data/puppet/code/environments/PuppetMasterFix/modules/profile_puppetagent_cron/manifests/init.pp:6:3 on node puppet01

environment is:

Centos7:

# rpm -qa | grep puppet
puppetlabs-release-pc1-1.0.0-1.el7.noarch
puppet-agent-1.3.4-1.el7.x86_64
puppetserver-2.2.1-1.el7.noarch
puppetdb-3.2.2-1.el7.noarch
puppetdb-termini-3.2.2-1.el7.noarch

puppet code is the profile for normal agents and the profile from puppetmaster, running on puppetmaster:

agent:

 class { '::puppet':
    allinone         => true,
    enable_mechanism => 'cron',
    manage_repos     => false,
    puppet_server    => $puppetmaster,
    runinterval      => $runinterval,
    structured_facts => true,
  }

master:

  class { '::puppet::master':
    server_type      => 'puppetserver',
    environmentpath  => $server_envs_dir,
    basemodulepath   => $server_envs_dir,
    java_ram         => '4G',
    autosign_method  => 'file',
    autosign_domains => ['*.xxx'],
    hiera_backends   => {'yaml' =>
      { 'datadir'    => "${server_envs_dir}/%{environment}/hieradata"}
    },
    hiera_hierarchy  => [
      'users',
      'nodes/%{::hostname}',
      'env/%{environment}/roles/%{role}',
      'env/%{environment}/common',
      'roles/%{role}',
      'ostype/%{operatingsystem}',
      'projects/%{project}',
      'common'
    ],
  }

Any ideas??

Thanks...

Lasse

@rendhalver
Copy link
Member

Which version of this module are you using?

@cloudsurf-digital
Copy link
Author

I'd tried with 2.2.0 but also with latest HEAD

@rendhalver
Copy link
Member

Are you sure you don't have any other classes, profiles and/or roles that have a class named puppet?

What other classes are you including on your puppet01 node?

What does this file look like?
/data/puppet/code/environments/PuppetMasterFix/modules/profile_puppetagent_cron/manifests/init.pp

@cloudsurf-digital
Copy link
Author

Are you sure you don't have any other classes, profiles and/or roles that have a class named puppet?

yes, code grep looks like:

$ grep -r puppet modules/ | grep class
modules//profile_puppetagent_cron/manifests/init.pp:class profile_puppetagent_cron {
modules//profile_puppetagent_cron/manifests/init.pp:  class { '::puppet':
modules//profile_puppetmaster/manifests/init.pp:class profile_puppetmaster {
modules//profile_puppetmaster/manifests/init.pp:  class { '::puppet::master':

What other classes are you including on your puppet01 node?

There are a few classes which are definded in the base role, but nothing but the puppetagent cron is relevant (see above grep)...

What does this file look like?
/data/puppet/code/environments/PuppetMasterFix/modules/profile_puppetagent_cron/manifests/init.pp

# Profile for the puppet agent
class profile_puppetagent_cron {
  $runinterval        = hiera('puppetagent::runinterval')
  $puppetmaster       = hiera('puppetagent::master')

  class { '::puppet':
    allinone         => true,
    enable_mechanism => 'cron',
    manage_repos     => false,
    puppet_server    => $puppetmaster,
    runinterval      => $runinterval,
    structured_facts => true,
  }
}
`

@rendhalver
Copy link
Member

I am not really sure whats going on there.
It looks like an error that used to show up randomly in puppet 2.7.x but I can't be sure.
In 2.7.x it would usually resolve it self without having to change anything.
I haven't seen that error since 2.7.x so I don't know how likely it is.

I would try taking out all the classes from the node and add them back in one at a time and see what happens.

@cloudsurf-digital
Copy link
Author

Very strange, i made the following change as you recommend and its compiles seamless...

-  class { '::puppet':
-    allinone         => true,
-    enable_mechanism => 'cron',
-    manage_repos     => false,
-    puppet_server    => $puppetmaster,
-    runinterval      => $runinterval,
-    structured_facts => true,
+  if ! $::role == 'puppetmaster' {
+    class { '::puppet':
+      allinone         => true,
+      enable_mechanism => 'cron',
+      manage_repos     => false,
+      puppet_server    => $puppetmaster,
+      runinterval      => $runinterval,
+      structured_facts => true,
+    }
   }
 }
diff --git a/modules/profile_puppetmaster/manifests/init.pp b/modules/profile_puppetmaster/manifests/init.pp
index ef8a86b..de56ece 100644
--- a/modules/profile_puppetmaster/manifests/init.pp
+++ b/modules/profile_puppetmaster/manifests/init.pp
@@ -11,6 +11,16 @@ class profile_puppetmaster {
     group  => 'puppet',
   }

+
+  class { '::puppet':
+    allinone         => true,
+    enable_mechanism => 'cron',
+    manage_repos     => false,
+    puppet_server    => $puppetmaster,
+    runinterval      => $runinterval,
+    structured_facts => true,
+  }
+


@jordigg
Copy link
Contributor

jordigg commented Apr 18, 2016

I was just trying the module and had the same error when trying to apply the puppet class on all my nodes and then the puppet::master to only the one I have defined with role puppetmaster.
The problem is that puppet::master already includes the puppet::agent role so it can't be defined twice. Check you only apply the puppet class or the puppet::master but not both on the same node.

@jordigg
Copy link
Contributor

jordigg commented Apr 18, 2016

Forget my last message, still having issue with it. I get errors that the master is duplicated on the config and always get Puppet v3 installed. I'm running the following on all nodes:

  include '::puppet'
  class { '::puppet::profile::agent':
    allinone      => true,
    collection    => 'PC1',
  }

Then just on the puppetmaster role manifest:

  include '::puppet::master'
  class { '::puppet::profile::master':
    autosign_method  => 'file',
    autosign_domains => ['*.redacted'],
  }

What am I doing wrong?

@jordigg
Copy link
Contributor

jordigg commented May 17, 2016

Found some more info regarding this issue. On my puppet config I have a common class that gets applied to everything, and then I have different classes that only get applied to specific "roles" managed by custom_facts.

When I put the agent class on my common class and the puppet class wrapped on the puppetmaster class it fails with the "duplicated declaration".

common.pp

class profiles::common::debian {

    class { '::puppet::profile::agent':
      allinone   => true,
      collection => 'PC1'
    }
}

puppetmaster.pp

class profiles::puppet::master {
    class { 'puppet::profile::master':
        server_type         => 'puppetserver',
        puppet_service_name => 'puppetserver',
        autosign_method     => 'file',
        autosign_domains    => ['*.internal.improbableworlds.net'],
        hiera_eyaml_version => installed,
        eyaml_keys          => false,
    }
}

If I put the ::puppet::profile::agent on the same manifest, together with the puppet::profile::master class, instead that in a separated manifest it works just fine.

puppetmaster.pp

class profiles::puppet::master {

    class { '::puppet::profile::agent':
      allinone   => true,
      collection => 'PC1'
    }

    class { 'puppet::profile::master':
        server_type         => 'puppetserver',
        puppet_service_name => 'puppetserver',
        autosign_method     => 'file',
        autosign_domains    => ['*.internal.improbableworlds.net'],
        hiera_eyaml_version => installed,
        eyaml_keys          => false,
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants