Ask Your Question

Duplicate declaration: Class[Main] is already declared

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

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:


include main.pp


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


Facter.add("current_user") do
  setcode do

What's the issue?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

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

Yep I can reproduce, main is one of the few [reserved keywords] (until my karma allows me to post links, * 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


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 -0500 )edit

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

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:


include main.pp


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


the use of import with classes is always a bad idea

ramindk gravatar imageramindk ( 2013-05-08 01:16:56 -0500 )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 -0500 )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


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

Seen: 1,434 times

Last updated: May 07 '13