Duplicate Declarations - Puppet

774 views
Skip to first unread message

Pedro César

unread,
Sep 8, 2014, 8:31:07 AM9/8/14
to puppet...@googlegroups.com
I'm not sure if I'm doing right or something I've done is stupid, but I have a question.

I have multiple hosts and multiple modules to manage these hosts, but eventually, I have same resources for different modules and the Puppet complaint about it.

I mean, I have two different modules that guarantee a folder be created, one of those modules I use to couple hosts and another one I use for the other hosts. However I need use both modules for one particular host and then my nightmare starts, because always Puppet complaint, saying: Error 400 on SERVER: Duplicate declaration.

I know is duplicated, but it's different modules and I have to guarantee both modules declare that resours.

Is there any way to skip this problem?

Peter Bukowinski

unread,
Sep 8, 2014, 9:09:02 AM9/8/14
to puppet...@googlegroups.com
The easiest way to resolve the problem is to move the folder resource into a separate class and make it a virtual resource. Then inside your two existing modules, include the virtual resource class, and then realize the virtual resource. Like all other resource declarations, you can only declare a virtual resource once, but you can realize it any number of times.

This puppet doc should give you all the information you need:

--
Peter Bukowinski

Message has been deleted

Pedro César

unread,
Sep 8, 2014, 9:42:07 AM9/8/14
to puppet...@googlegroups.com
Thanks for your answer Peter. I appreciate that.

   Yes, it's a really good idea, I did that before but it's kind of weird. Because while I'm building more and more modules I have to change the module that contains a virtual resource, you know seems a little silly.

   And I was wondering for a different idea or explanation, because I can't understand why Puppet can't handle that situation.


Best regards.

~Pedro Cesar.

Trevor Vaughan

unread,
Sep 8, 2014, 9:45:45 AM9/8/14
to puppet...@googlegroups.com
I also believe it to be silly.

There have been several discussions over time regarding allowing multiple *identical* resources to exist in the catalog.

I, personally, am in favor of this approach but it tends to get shot down as 'allowing sloppy module design'.  And, yes, it does. But I also think that it saves time since you don't have to refactor your code a million times as you add new components.

Trevor

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/cf45b640-cda2-478b-96ea-eb1c15e50172%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Trevor Vaughan
Vice President, Onyx Point, Inc
(410) 541-6699
tvau...@onyxpoint.com

-- This account not approved for unencrypted proprietary information --

Felix Frank

unread,
Sep 8, 2014, 10:06:17 AM9/8/14
to puppet...@googlegroups.com
On 09/08/2014 03:45 PM, Trevor Vaughan wrote:
> I also believe it to be silly.
>
> There have been several discussions over time regarding allowing
> multiple *identical* resources to exist in the catalog.
>
> I, personally, am in favor of this approach but it tends to get shot
> down as 'allowing sloppy module design'. And, yes, it does. But I also
> think that it saves time since you don't have to refactor your code a
> million times as you add new components.
>
> Trevor

Eh, that's not entirely true :-)

It's in fact still on the agenda, i.e.
https://tickets.puppetlabs.com/browse/PUP-1968

But it turns out (surprise, surprise), that it's Really Hard to
implement, s.a. https://projects.puppetlabs.com/issues/18490#note-17

I believe that nobody is actively working on this at this time, and even
if anyone steps forward right about now, it won't be a quick fix I think.

Cheers,
Felix

Warren Clarke

unread,
Sep 8, 2014, 1:04:37 PM9/8/14
to puppet...@googlegroups.com
Hi Pedro,

A work around would be to declare the resource as follows in your module(s):

if !defined (File['path_to_your_directory']) {
  file { 'path_to_your_directory' :
    ensure = directory,
  }
}

That should resolve the "Duplicate declaration" error you are getting.
Hope this helps. 

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

Felix Frank

unread,
Sep 9, 2014, 7:41:00 PM9/9/14
to puppet...@googlegroups.com
On 09/08/2014 05:27 PM, Warren Clarke wrote:
Hi Pedro,

A work around would be to declare the resource as follows in your module(s):

if !defined (File['path_to_your_directory']) {
  file { 'path_to_your_directory' :
    ensure = directory,
  }
}

That should resolve the "Duplicate declaration" error you are getting.
Hope this helps. 

*sigh*

Well, it kind of does, but please, please don't.

This goblin crops up each couple of years here again. I suppose it will continue to do so until we find a way to put the defined() function to rest. I.e., remove it from the language.

John produced some good writeups on the list back in '12.
https://groups.google.com/d/msg/puppet-users/Fvl0aOe4RPE/-k60j2QSID0J

We have made some progress since then, in the form of a module.
https://forge.puppetlabs.com/ffrank/constraints

It allows you to design a clean and non-ambiguous, if somewhat less convenient manifest. We're not sure whether this will suffice to deprecate the defined function (it may have other uses, after all), and perhaps it'll stay until real duplication is possible. As I wrote earlier, that will be a while.

A better workaround with the current toolset are indeed virtual resources, as Peter stated, or wrapping the problematic resource in a class, if that is feasible.

Regards,
Felix
Reply all
Reply to author
Forward
0 new messages