Hello I get the following error: err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate definition: Class[paramclassexample] is already defined in file /etc/puppetlabs/puppet/manifests/site.pp at line 152; cannot redefine at /etc/puppetlabs/puppet/manifests/site.pp:155 on node cmnapwbe040 Let''s look at the Puppet Documentation code on parameterized classes: # /etc/puppetlabs/puppet/modules/paramclassexample/manifests/ init.pp class paramclassexample ($value1, $value2 = "Default value") { notify {"Value 1 is ${value1}.":} notify {"Value 2 is ${value2}.":} } /etc/puppetlabs/puppet/manifests/site.pp class {''paramclassexample'': value1 => ''Something'', value2 => ''Something else'', } class {''paramclassexample'': value1 => ''Other'', } My problem is that I need to call the class multiple times in the site.pp file but with different parameters. How can I do that? Thank you Olivier -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Christopher Wood
2012-Jan-31 15:46 UTC
Re: [Puppet Users] Error 400 on SERVER: Duplicate definition
This sounds like you want a define rather than a class. http://docs.puppetlabs.com/guides/language_guide.html#defined-resource-types I end up with something like this (gross, horrible, works, nfs client installation not shown): define mail::mount ($mountpoint, $source) { include nfs::client file { $mountpoint: ensure => directory, } mount { $mountpoint: ensure => mounted, device => $source, options => ''tcp,rsize=32768,wsize=32768,hard,nointr,timeo=600,retrans=2,mountvers=3,nfsvers=3'', fstype => ''nfs'', atboot => true, require => [File[$mountpoint], Class[''nfs::client'']], } } mail::mount { ''mail0'': mountpoint => ''/mail/mail0'', source => ''filer:/mail0'' } mail::mount { ''mail1'': mountpoint => ''/mail/mail1'', source => ''filer:/mail1'' } On Tue, Jan 31, 2012 at 07:39:28AM -0800, Olivier wrote:> Hello > > I get the following error: > err: Could not retrieve catalog from remote server: Error 400 on > SERVER: Duplicate definition: Class[paramclassexample] is already > defined in file /etc/puppetlabs/puppet/manifests/site.pp at line 152; > cannot redefine at /etc/puppetlabs/puppet/manifests/site.pp:155 on > node cmnapwbe040 > > Let''s look at the Puppet Documentation code on parameterized classes: > > # /etc/puppetlabs/puppet/modules/paramclassexample/manifests/ > init.pp > class paramclassexample ($value1, $value2 = "Default value") { > notify {"Value 1 is ${value1}.":} > notify {"Value 2 is ${value2}.":} > } > > > /etc/puppetlabs/puppet/manifests/site.pp > class {''paramclassexample'': > value1 => ''Something'', > value2 => ''Something else'', > } > class {''paramclassexample'': > value1 => ''Other'', > } > > My problem is that I need to call the class multiple times in the > site.pp file but with different parameters. How can I do that? > > Thank you > > Olivier > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Felix Frank
2012-Jan-31 15:46 UTC
Re: [Puppet Users] Error 400 on SERVER: Duplicate definition
Hi, On 01/31/2012 04:39 PM, Olivier wrote:> My problem is that I need to call the class multiple times in the > site.pp file but with different parameters.this is not possible. It doesn''t really make sense either. Classes in puppet are unlike classes in other languages like C# or Java that you may be familiar with. There are no instances to classes. Each class is a singleton entity. A host declares a given class or it doesn''t. Once or never. As for parameterized classes, the parameter values must have one definitive value for each given node. I advise your share the "real world" problem you need solved, so that the community can advise you on the best way to solve your problem by hand. You probably don''t need class parameterization at all, but from your description so far, I cannot guess what approach would fit you best. Cheers, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Felix Frank
2012-Jan-31 15:52 UTC
Re: [Puppet Users] Error 400 on SERVER: Duplicate definition
On 01/31/2012 04:46 PM, Christopher Wood wrote:> This sounds like you want a define rather than a class.Possibly, but not yet determined ;-)> gross, horribleHow so? It''s not a bad example. If you dislike the data redundancy, I suggest: define mail::mount($mount_base="/mail") { include nfs::client $mountpoint = "$mount_base/$name" file { $mountpoint: ensure => directory, } mount { $mountpoint: ensure => mounted, device => "filer:/$name", options => ''tcp,rsize=32768,wsize=32768,hard,nointr,timeo=600,retrans=2,mountvers=3,nfsvers=3'', fstype => ''nfs'', atboot => true, require => [File[$mountpoint], Class[''nfs::client'']], } } and then mail::mount { [ ''mail0'', ''mail1'' ]: } IMHO, there''s not much more that desperately needs changing in your code. Cheers, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Christopher Wood
2012-Jan-31 16:07 UTC
Re: [Puppet Users] Error 400 on SERVER: Duplicate definition
On Tue, Jan 31, 2012 at 04:52:31PM +0100, Felix Frank wrote:> On 01/31/2012 04:46 PM, Christopher Wood wrote: > > This sounds like you want a define rather than a class. > > Possibly, but not yet determined ;-) > > > gross, horrible > > How so? It''s not a bad example. If you dislike the data redundancy, I > suggest:I prefer my disclaimer to "use at your own risk". I hope it promotes people reading and understanding what follows, instead of blindly cutting and pasting. It also covers me in case I''m unaware of my actual eruptions of awful. In my case, I''m fine with the data redundancy. The source path is the same as written in /etc/exports on the server, and the mount path is the same as in /etc/fstab on the client (albeit obfuscated slightly for this list). My standard is that somebody solving a problem at 04:00 shouldn''t have to dig too deeply into a manifest to figure out what goes where, for a broad definition of how conscious I am at 04:00.> define mail::mount($mount_base="/mail") { > > include nfs::client > > $mountpoint = "$mount_base/$name" > > file { $mountpoint: ensure => directory, } > > mount { $mountpoint: > ensure => mounted, > device => "filer:/$name", > options => > ''tcp,rsize=32768,wsize=32768,hard,nointr,timeo=600,retrans=2,mountvers=3,nfsvers=3'', > fstype => ''nfs'', > atboot => true, > require => [File[$mountpoint], Class[''nfs::client'']], > } > > } > > and then > > mail::mount { [ ''mail0'', ''mail1'' ]: } > > IMHO, there''s not much more that desperately needs changing in your code. > > Cheers, > Felix > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Olivier
2012-Jan-31 17:53 UTC
[Puppet Users] Re: Error 400 on SERVER: Duplicate definition
This is a great example, but I need one more detail. Is "mail" a class or a module? Thank you -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Christopher Wood
2012-Jan-31 18:01 UTC
Re: [Puppet Users] Re: Error 400 on SERVER: Duplicate definition
I can''t completely answer your question unless you point to the section you''re asking about. (Possibly reply to my earlier post, quoting what I posted, and insert your question right after the puzzling part.) I''ll try anyway. "mail::mount" is a define specified in the "mail" module. See: http://docs.puppetlabs.com/guides/modules.html Do yourself a favour and put your classes and defines in modules, starting now. As your site grows you''ll need this to separate out the discrete parts of your infrastructure. On Tue, Jan 31, 2012 at 09:53:32AM -0800, Olivier wrote:> This is a great example, but I need one more detail. Is "mail" a class > or a module? > Thank you > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.