1

I have a definition in my puppet manifests called postgresql::user

I have put in the following, to make sure puppet doesn't try to do something twice:

if !defined (Postgresql::User["dbuser"]) { 
        postgresql::user { "dbuser": 
            ensure => present
        } 
    }

However I am still getting the errors in puppetd --test

err: Could not retrieve catalog: Duplicate definition: Postgresql::User[dbuser] is already defined in file /etc/puppet/modules/dbserver/manifests/postgresql8-3.pp at line 22; cannot redefine at /etc/puppet/modules/dbserver/manifests/postgresql8-3.pp:7 on node mynode

I have a feeling it doesn't like the capitalisation and `::' when checking if defined. Is there way to escape this?

bobinabottle
  • 579
  • 2
  • 7
  • 19

1 Answers1

4

The problem is not the capitalization, but rather duplicate definition of the resource in /etc/puppet/modules/dbserver/manifests/postgresql8-3.pp. Here's a simple manifests demonstrating this:

define foo::bar {
  notify { $name: }
}

foo::bar { "hello": }

if !defined (Foo::Bar['hello']) {
  foo::bar { "hello": }
}

If you change !defined to defined, you will see the duplicate resource error similar to your error. I would post your full manifest rather than a snippet.

Also try virtual resource (@type) if this is a problem where two modules need to realize the same resource.

Nan Liu
  • 514
  • 2
  • 4