duplicate resource with inherit and puppet apply

79 views
Skip to first unread message

Toni Schmidbauer

unread,
Sep 28, 2016, 8:31:07 AM9/28/16
to Puppet Users
hi,

it's a stupid example but nevertheless it would be interesting to now
why the following throws a duplicate resource error under puppet 3.7.4
and puppet 4.2.1

test/manifests/init.pp:

# start puppet code
class test inherits test::subclass {
notify { 'hello?': }
}
include test
#end puppet code

test/manifests/subclass.pp:

# start puppet code
class test::subclass {}
# end puppet code

running

# puppet apply --modulepath=.../modules .../modules/test/init.pp

throws a duplicate resource error (4.2.1 error message):

Error: Evaluation Error: Error while evaluating a Resource Statement,
Duplicate declaration: Notify[hello?] is already declared in file
/vagrant/modules/test/manifests/init.pp:2; cannot redeclare at
/vagrant/modules/test/manifests/init.pp:2 at /vagrant/modules/test/manif
ests/init.pp:2:3 on node centos7.eb.lan.at

if i remove 'inherits test::subclass' from init.pp it works:

Notice: Compiled catalog for centos7.eb.lan.at in environment production
in 0.32 seconds
Notice: hello?
Notice: /Stage[main]/Test/Notify[hello?]/message: defined 'message' as
'hello?'
Notice: Applied catalog in 0.02 seconds

also removing 'include test' in init.pp and running

puppet apply --modulepath=/vagrant/modules /vagrant/modules/test/manifests/init.pp -e 'include test'

works

Notice: Compiled catalog for centos7.eb.lan.at in environment production
in 0.29 seconds
Notice: hello?
Notice: /Stage[main]/Test/Notify[hello?]/message: defined 'message' as
'hello?'
Notice: Applied catalog in 0.02 seconds

any hints?

thanks for your time and help

toni

Henrik Lindberg

unread,
Sep 28, 2016, 9:55:15 PM9/28/16
to puppet...@googlegroups.com
Yes, then it does nothing - so that would work :-)

> puppet apply --modulepath=/vagrant/modules /vagrant/modules/test/manifests/init.pp -e 'include test'
>
> works
>
> Notice: Compiled catalog for centos7.eb.lan.at in environment production
> in 0.29 seconds
> Notice: hello?
> Notice: /Stage[main]/Test/Notify[hello?]/message: defined 'message' as
> 'hello?'
> Notice: Applied catalog in 0.02 seconds
>
> any hints?
>

I tried this on latest puppet:

=== test.pp
class test::subclass {}
class test inherits test::subclass {
notify { 'hello?': }
}
include test

puppet apply test.pp

And that works - does that fail for you ?

- henrik

> thanks for your time and help
>
> toni
>


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Toni Schmidbauer

unread,
Sep 30, 2016, 3:03:06 PM9/30/16
to Henrik Lindberg, puppet...@googlegroups.com
did some more tests with puppet 4.7. so the above works but if i move
tests::subclass into a separate file (subclass.pp) in the manifests
folder puppet apply fails with duplicate resource.

my source code layout:

├── manifests
│   ├── init.pp
│   └── subclass.pp
└── tests
└── init.pp

manifests/init.pp:

## code
class test inherits test::subclass {
notify { 'hello world': }
}

include test
# end code

manifests/subclass.pp:

## code
class test::subclass {}
# end code

tests/init.pp:

## code
include test
# end code

i run the code with the following command

puppet apply --modulepath=/vagrant/modules manifests/init.pp

if i use

puppet apply --modulepath=/vagrant/modules tests/init.pp
^
|- HEADS UP

puppet apply works.

thanks for your help

toni

jcbollinger

unread,
Oct 3, 2016, 9:48:26 AM10/3/16
to Puppet Users
The behavior you describe seems buggy to me, but your manifests are also unusual.  Specifically, it is strange for test/manifests/init.pp to contain a top-scope declaration.  It is especially strange for that declaration to be "include test" because this is the very same file that would be evaluated, if needed, as a result of evaluating that declaration.

I suppose the reason for that is to make the manifest usable both directly with 'puppet apply' and as an ordinary module manifest, and I think that should work.  Nevertheless, it looks to me like an awkward mix of Puppet module and site manifests, and even if it worked, I would not recommend structuring your manifests like that.  I observe that your workaround involves partially splitting the site manifest part from the module manifest part, but personally, I'd go farther and take the site manifest part completely out of the module.

As I said, however, I think it should work, and even if there were a reason for it not to work, the error message that is emitted is bizarre for the code presented.  I think that's probably indicative that the code is doing something unexpected by its authors.  I encourage you to file a ticket for buggy behavior here, but if you do so, do not neglect to mention the diagnostic because at the very least, there are grounds here for an RFE around improving the diagnostic.


John

Henrik Lindberg

unread,
Oct 3, 2016, 8:36:43 PM10/3/16
to puppet...@googlegroups.com
On 03/10/16 15:48, jcbollinger wrote:
>
>
> On Friday, September 30, 2016 at 2:03:06 PM UTC-5, Toni Schmidbauer wrote:
>
Top scope logic in autoloaded code have very strange effects and should
not be used. At some point in the future it will probably be forbidden
to have any code outside of the structure that is supposed to be in an
autoloaded file.

> I suppose the reason for that is to make the manifest usable both
> directly with 'puppet apply' and as an ordinary module manifest, and I
> think that /should/ work. Nevertheless, it looks to me like an awkward
> mix of Puppet module and site manifests, and even if it worked, I would
> not recommend structuring your manifests like that. I observe that your
> workaround involves partially splitting the site manifest part from the
> module manifest part, but personally, I'd go farther and take the site
> manifest part completely out of the module.
>

Agree with John here.

- henrik

> As I said, however, I think it should work, and even if there were a
> reason for it not to work, the error message that is emitted is bizarre
> for the code presented. I think that's probably indicative that the
> code is doing something unexpected by its authors. I encourage you to
> file a ticket for buggy behavior here, but if you do so, do not neglect
> to mention the diagnostic because at the very least, there are grounds
> here for an RFE around improving the diagnostic.
>
>
> John
>
> --
> 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
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/fec40211-95a6-4e3f-94ae-e7ea37069bdc%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/fec40211-95a6-4e3f-94ae-e7ea37069bdc%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Toni Schmidbauer

unread,
Oct 5, 2016, 3:43:07 PM10/5/16
to Henrik Lindberg, puppet...@googlegroups.com
>Henrik Lindberg <henrik....@puppet.com> writes:
>> On 03/10/16 15:48, jcbollinger wrote:
>> The behavior you describe seems buggy to me, but your manifests are also
>> unusual. Specifically, it is strange for test/manifests/init.pp to
>> contain a top-scope declaration. It is especially strange for that
>> declaration to be "include test" because this is the very same file that
>> would be evaluated, if needed, as a result of evaluating that
>> declaration.

yes, i agree fully. this is not the usual way to write modules. i was
just showing a collegue who's getting started with puppet an example
module and while playing around we found this rather strange behaviour.

> Top scope logic in autoloaded code have very strange effects and
> should not be used. At some point in the future it will probably be
> forbidden to have any code outside of the structure that is supposed
> to be in an autoloaded file.

ok, thanks for the clarification.

>> As I said, however, I think it should work, and even if there were a
>> reason for it not to work, the error message that is emitted is bizarre
>> for the code presented. I think that's probably indicative that the
>> code is doing something unexpected by its authors. I encourage you to
>> file a ticket for buggy behavior here, but if you do so, do not neglect
>> to mention the diagnostic because at the very least, there are grounds
>> here for an RFE around improving the diagnostic.

ok, once again thanks for your time. i'll file a ticket.

thank you both
toni
Reply all
Reply to author
Forward
0 new messages