What is wrong with this code?

22 views
Skip to first unread message

Marc

unread,
Aug 19, 2014, 10:33:57 AM8/19/14
to puppet...@googlegroups.com
Hi all,

The code snippet below is an isolation of the problem I am facing.
I don't understand why this produces a duplicate declaration.
Can anyone give an explanation?

$ cat test.pp 
class foo { contain foo::bar }
class foo::bar { class { 'bar': } }
class bar { notify { 'hello': } }
include foo

$ puppet apply test.pp
Error: Duplicate declaration: Class[Foo::Bar] is already declared; cannot redeclare at /home/marc/test.pp:2 on node carbon.demo.lan
Error: Duplicate declaration: Class[Foo::Bar] is already declared; cannot redeclare at /home/marc/test.pp:2 on node carbon.demo.lan

Thank you!
Marc

Craig Dunn

unread,
Aug 19, 2014, 10:55:53 AM8/19/14
to puppet...@googlegroups.com
On Tue, Aug 19, 2014 at 12:33 PM, Marc <marc.vi...@gmail.com> wrote:

Hi all,

The code snippet below is an isolation of the problem I am facing.
I don't understand why this produces a duplicate declaration.
Can anyone give an explanation?

$ cat test.pp 
class foo { contain foo::bar }
class foo::bar { class { 'bar': } }
class bar { notify { 'hello': } }
include foo


Within class foo::bar "bar" is being found in local scope (eg: it's declaring itself).  Thats why fully qualified is always a good way to go to be explicit about these things.  You need to explicitly require ::bar, not bar...


class foo::bar { class { '::bar': } }

Craig
 

--
Enviatics | Automation and configuration management
http://www.enviatics.com | @Enviatics
Puppet Training http://www.enviatics.com/training/

Marc

unread,
Aug 19, 2014, 1:17:28 PM8/19/14
to puppet...@googlegroups.com
Hi Craig,

That makes sense. In fact, now I remember this is not the first time it bites me.
I'll stick a post-it in my forehead.

Thank you!
Reply all
Reply to author
Forward
0 new messages