Ask Your Question

Duplicate declaration error occured, even if I use ensure_resource.

asked 2013-08-04 19:49:45 -0600

cynipe gravatar image

updated 2013-08-04 19:52:14 -0600

I'm wondering that why duplicate declaration error occured.

Suppose I have following statements which could be solve a duplication error:

if ! defined(Package['libxslt']) {
   package {'libxslt': ensure => present, }


include stdlib

Then, include class that contains package libxslt.

Any idea?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-08-07 06:31:01 -0600

nibalizer gravatar image

updated 2013-08-07 06:41:01 -0600

What you're essentially doing here is trying to use the defined() function to evade duplicate definition errors. This kind of check-first, then-do programming isn't going to work very well in Puppet because evaluation order in Puppet is random.

What you're actually trying to do, I think, is to manage packages on your system. Specifically, you want to manage trivial packages. That is, packages that don't have to be installed in any order, no special options, no dependent resources. Everyone eventually ends up here, it seems. There are just long-ish lists of packages that you want to ... (more)

edit flag offensive delete link more


sorry for being late, and thank you very much for your detailed explanation. I will look into puppet-module-singleton. Thank you!!

cynipe gravatar imagecynipe ( 2013-08-29 03:15:24 -0600 )edit

edit: didn't read the question first, only the answer. Most of this comment is irrelevant. Carry on, nothing to see here. :-). This is exactly what I was looking for ...(more)

reidmv gravatar imagereidmv ( 2014-01-07 11:34:55 -0600 )edit

Unless I'm missing something here, doesn't the singleton option require that all modules on the system use the singleton module? My initial experimentation seems to indicate that. I ...(more) gravatar ( 2014-02-07 13:04:35 -0600 )edit

answered 2013-08-06 21:52:54 -0600

GregLarkin gravatar image

Please check the reference for the defined function here. In particular, the documentation states:

Resource declarations are checked using resource references, e.g. defined( File['/tmp/myfile'] ). Checking whether a given resource has been declared is, unfortunately, dependent on the parse order of the configuration...

The example given in the documentation is almost identical to the code that you posted.

Is there a reason why you can't simply centralize the use of ensure_packages in a single manifest and include once?

edit flag offensive delete link more


sorry for being late. Because, conflicting occurred between my module and other module.

cynipe gravatar imagecynipe ( 2013-08-29 03:13:29 -0600 )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

1 follower


Asked: 2013-08-04 19:49:45 -0600

Seen: 4,405 times

Last updated: Aug 07 '13