Ask Your Question
2

Duplicate declaration: Class[Main] is already declared

asked 2013-05-07 17:16:13 -0600

gsingh93 gravatar image

I'm getting the following error when running puppet apply manifests/site.pp --modulepath=modules on a server:

Duplicate declaration: Class[Main] is already declared

Here is my directory layout:

.
|-- manifests
|   `-- site.pp
`-- modules
    `-- main
        |-- files
        |   |-- bashrc
        |-- lib
        |   `-- facter
        |       `-- current_user.rb
        `-- manifests
            `-- init.pp

Here is my code:

manifests/site.pp

include main.pp

modules/main/manifests/init.pp

class main {
  file { "/home/$::current_user/.bashrc":
    source => "puppet:///modules/main/bashrc"
  }
}

modules/main/lib/current_user.rb

Facter.add("current_user") do
  setcode do
    Facter::Util::Resolution.exec('/usr/bin/whoami')
  end
end

What's the issue?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2013-05-07 17:46:42 -0600

Yep I can reproduce, main is one of the few [reserved keywords] docs.puppetlabs.com/puppet/2.7/reference/lang_reserved.html#reserved-class-names (until my karma allows me to post links, *.puppetlabs.com should be whitelisted...

main — Puppet automatically creates a main class, which contains any resources not contained by any other class.

Also :

include main

ie class name not filename.

edit flag offensive delete link more

Comments

Thanks, renaming the module worked. I'm not sure about the second thing you're saying though. Are you saying I'm not supposed to use the class name?

gsingh93 gravatar imagegsingh93 ( 2013-05-07 20:43:05 -0600 )edit
0

answered 2013-05-07 17:58:24 -0600

Jeff Johnson gravatar image

I was able to duplicate your issue. I was able to fix it by making the following change in /etc/pupet/manifests/site.pp:

old:

include main.pp

new:

import "main"

After I made the change above, my puppet run was successful.

I'm pretty new to Puppet myself. As near as I can tell, when you use the include keyword, Puppet creates a Class with that name. What you really want to do is import your "Main" module, which loads your main.pp into the puppet master's catalog. Or something like that.

edit flag offensive delete link more

Comments

the use of import with classes is always a bad idea

ramindk gravatar imageramindk ( 2013-05-08 01:16:56 -0600 )edit

I did a little more reading, and you're right - "import" w/classes is a pretty bad solution to this problem. The other answer is correct, and mine really isn't.

Jeff Johnson gravatar imageJeff Johnson ( 2013-05-08 17:25:31 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-05-07 17:16:13 -0600

Seen: 1,628 times

Last updated: May 07 '13