Duplicate definition of resources in the same class

1,212 views
Skip to first unread message

Rost

unread,
Aug 10, 2012, 6:40:21 AM8/10/12
to puppet...@googlegroups.com
Hi all,

I am struggling on how to do this :

$path = '/tmp/lib'

file { $path:
   ensure => directory,
   recurse => true,
   purge => true,
}

file { $path:
   ensure => directory,
   resurce => true,
   source => 'puppet:///modules/jboss/lib
}

When puppet compiles the manifest, I get the following error: 

 Duplicate declaration: File[/tmp/lib] is already declared in file /etc/puppet/modules/srhjboss/manifests/purge.pp at line 4; cannot redeclare at /etc/puppet/modules/srhjboss/manifests/purge.pp:10 on node frparsrnlinnto

It seems that i can't purge the directory before to copy the new one from the source.

Suggestions ??
Thanks

Axel Bock

unread,
Aug 10, 2012, 6:55:38 AM8/10/12
to puppet...@googlegroups.com
easy. every resource may only be defined _once_.
you try ... twice (file { $path : ... } and file { $path: ... }, right?)

why not simply


file { $path:
   ensure => directory,
   recurse => true,
   purge => true,
   source => 'puppet:///modules/jboss/lib
}

?

if you _need_ to do this twice for whatever reason, do something like this (but you SHOULD NOT):

file { "$path/0":
   $path => $path,
   ensure => directory,
   recurse => true,
   purge => true,
}

file { "$path/1":
   path => $path,
   ensure => directory,
   resurce => true,
   source => 'puppet:///modules/jboss/lib
}

cause puppet identifies the resource by the title, which must differ, which it does not. note THAT THIS IS NOT THE RIGHT WAY :) .


HTH & greetings,
Axel.

Rost

unread,
Aug 10, 2012, 7:22:31 AM8/10/12
to puppet...@googlegroups.com
Hi Axel

Thanks a lot, you solution is right.
Reply all
Reply to author
Forward
0 new messages