<Derek.Whayman@barclayscapital.com>
2007-May-24 09:02 UTC
Reusing definitions - need to pass variable in the title
I recently tidied up a class/definition combo that sets /etc/issue and /etc/issue.net. This failed: define issuefile($path) { file { issue: owner => root, group => root, mode => 0644, content => template("issue_conf") } } class issue { issuefile { "issue": path => "/etc/issue" } } class issuenet { issuefile { "issue.net": path => "/etc/issue.net" } } class banners { include issue include issuenet } With err: Could not retrieve configuration: Duplicate definition: File[issue] is already defined in file /etc/puppet/manifests/classes/banners.pp at line 22; cannot redefine at /etc/puppet/manifests/classes/banners.pp:22 Changing the issuefile definition to this makes it work perfectly: define issuefile($path) { file { $path: owner => root, group => root, mode => 0644, content => template("issue_conf") } } Where you explicitly set the title of the definition to something unique, i.e. $path. I''m clearly still in the perl-programming mindset, but I thought that you could get away with the former (drawing on the LanguageTutorial wiki doc). What am I missing? Cheers, Derek ------------------------------------------------------------------------ For important statutory and regulatory disclosures and more information about Barclays Capital, please visit our web site at http://www.barcap.com. Internet communications are not secure and therefore the Barclays Group does not accept legal responsibility for the contents of this message. Although the Barclays Group operates anti-virus programmes, it does not accept responsibility for any damage whatsoever that is caused by viruses being passed. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Barclays Group. Replies to this email may be monitored by the Barclays Group for operational or business reasons. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. ------------------------------------------------------------------------
Ceri Storey
2007-May-24 09:55 UTC
Re: Reusing definitions - need to pass variable in the title
Derek.Whayman@barclayscapital.com wrote:> Where you explicitly set the title of the definition to something > unique, i.e. $path.That''s precisely it. Each different resource declaration needs to have a unique "name", otherwise puppet gets confused. I think what might be confusing people on this is that puppet has a flat namespace for resource names, rather than one derived from the module / component (so you''d end up with module::issuefile(issue_net)::issue (Very C++). For me, the current arrangement works reasonably well. Each resource title uniquely identifies a thing of that class (ie: it''d be the full pathname of a file, or the name of a yum repository), so if we were to start introducing a more complex namespace, it''d potentially lead to non-idempotent behaviour (eg: flip-flopping between two states).
David Schmitt
2007-May-24 10:03 UTC
Re: Reusing definitions - need to pass variable in the title
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 24 May 2007, Derek.Whayman@barclayscapital.com wrote:> I recently tidied up a class/definition combo that sets /etc/issue and > /etc/issue.net. This failed: > > define issuefile($path) { > file { issue: > owner => root, > group => root, > mode => 0644, > content => template("issue_conf") > } > } > > class issue { > issuefile { "issue": > path => "/etc/issue" > } > } > > class issuenet { > issuefile { "issue.net": > path => "/etc/issue.net" > } > } > > class banners { > include issue > include issuenet > } > > With > > err: Could not retrieve configuration: Duplicate definition: File[issue] > is already defined in file /etc/puppet/manifests/classes/banners.pp at > line 22; cannot redefine at /etc/puppet/manifests/classes/banners.pp:22 > > Changing the issuefile definition to this makes it work perfectly: > > define issuefile($path) { > file { $path: > owner => root, > group => root, > mode => 0644, > content => template("issue_conf") > } > } > > Where you explicitly set the title of the definition to something > unique, i.e. $path.That''s because the second form is correct, while your first try was not.> I''m clearly still in the perl-programming mindset, but I thought that > you could get away with the former (drawing on the LanguageTutorial wiki > doc). > > What am I missing?Two things: 1) if you don''t specify the path to a file in the title/namevar (the part between { and : ), then you need to add path=>$path 2) there cannot be two resources of the same (type,title) in the configuration of a node Regards, David - -- - - hallo... wie gehts heute? - - *hust* gut *rotz* *keuch* - - gott sei dank kommunizieren wir über ein septisches medium ;) -- Matthias Leeb, Uni f. angewandte Kunst, 2005-02-15 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGVWMK/Pp1N6Uzh0URAn6sAJwKkcpfPhcHnYmqNv6/74zbGeRuUQCgilyq FlLOQBJ+zTmIoYLgPpxpt28=Ee0O -----END PGP SIGNATURE-----