Hello, I have a define in which I need to loop through an array. That worked well, until I needed to loop through a second instance of an array in another call to that define that just so happens to have the same data in it. Now I get the following error: err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate definition: Reprepro::Repo::Dummyloop[lenny] is already defined in file /etc/puppet/modules/reprepro/manifests/repo.pp at line 22; cannot redefine at /etc/puppet/modules/reprepro/manifests/repo.pp:22 on node stage02.local Here''s a dumbed down version of the define: =# dummy define just to be able to iterate through an array.. define reprepro::repo::dummyloop($distribution) { file { "${reprepro::params::repo_base_dir}/${distribution}/conf/override.${name}": ensure => "present" } } define reprepro::repo($distribution, $codenames, $origin, $label, $description, $architectures = ''i386 amd64 source'', $suites ''stable'', $components = ''main'', $signed = false) { include reprepro::params <snip> reprepro::repo::dummyloop { $codenames: distribution => $distribution, codename => $codenames } <snip> } = ideas on how to solve this properly are more then welcome. Puppet 2.6.2 cheers, -- Walter Heck -- follow @walterheck on twitter to see what I''m up to! -- Check out my new startup: Server Monitoring as a Service @ http://tribily.com Follow @tribily on Twitter and/or ''Like'' our Facebook page at http://www.facebook.com/tribily -- 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-05 13:32 UTC
Re: [Puppet Users] helper define for looping through array
Hi, On 01/05/2012 01:51 PM, Walter Heck wrote:> until I needed to loop through a second instance of an array in > another call to that define that just so happens to have the same data > in it. Now I get the following error:this is a cute problem description indeed ;-) What problem are you trying to solve? What should puppet do when you feed it the same input twice? It strikes me as quite desirable that puppet will *not* allow you to try and create the same range of files from different places in your manifest. 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.
Walter Heck
2012-Jan-05 13:36 UTC
Re: [Puppet Users] helper define for looping through array
That''s the fun part: the $distribution parameter that the define recieves is different the second time, so it would create the files in a different location. Normally we could solve this by making the $name unique, but since that is what is used to make the array magic happen, I cannot go and make that $name unique, can I? Walter On Thu, Jan 5, 2012 at 14:32, Felix Frank <felix.frank@alumni.tu-berlin.de> wrote:> Hi, > > On 01/05/2012 01:51 PM, Walter Heck wrote: >> until I needed to loop through a second instance of an array in >> another call to that define that just so happens to have the same data >> in it. Now I get the following error: > > this is a cute problem description indeed ;-) > > What problem are you trying to solve? > What should puppet do when you feed it the same input twice? > > It strikes me as quite desirable that puppet will *not* allow you to try > and create the same range of files from different places in your manifest. > > 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. >-- Walter Heck -- follow @walterheck on twitter to see what I''m up to! -- Check out my new startup: Server Monitoring as a Service @ http://tribily.com Follow @tribily on Twitter and/or ''Like'' our Facebook page at http://www.facebook.com/tribily -- 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-05 13:41 UTC
Re: [Puppet Users] helper define for looping through array
On 01/05/2012 02:36 PM, Walter Heck wrote:> That''s the fun part: the $distribution parameter that the define > recieves is different the second time, so it would create the files in > a different location. Normally we could solve this by making the $name > unique, but since that is what is used to make the array magic happen, > I cannot go and make that $name unique, can I?Ah, now that problem does ring a bell or two. What I''ve done in the past is this: 1. create a copy of the array 2. mutilate this copy using regsubst(), i.e. uniquify the names (this will typically involve $name from the calling scope) 3. make your looping define retrieve the original array entries (by another use of regsubst() I believe) It''s ugly and probably not performant, but it has worked before... ;/ HTH, 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.
Walter Heck
2012-Jan-05 13:45 UTC
Re: [Puppet Users] helper define for looping through array
I was afraid this was going to be the only solution. I guess we could really do with more sane handling of arrays in puppet. This is a workaround to make a workaround work.. On Thu, Jan 5, 2012 at 14:41, Felix Frank <felix.frank@alumni.tu-berlin.de> wrote:> On 01/05/2012 02:36 PM, Walter Heck wrote: >> That''s the fun part: the $distribution parameter that the define >> recieves is different the second time, so it would create the files in >> a different location. Normally we could solve this by making the $name >> unique, but since that is what is used to make the array magic happen, >> I cannot go and make that $name unique, can I? > > Ah, now that problem does ring a bell or two. > > What I''ve done in the past is this: > > 1. create a copy of the array > 2. mutilate this copy using regsubst(), i.e. uniquify the names (this > will typically involve $name from the calling scope) > 3. make your looping define retrieve the original array entries (by > another use of regsubst() I believe) > > It''s ugly and probably not performant, but it has worked before... ;/ > > HTH, > 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. >-- Walter Heck -- follow @walterheck on twitter to see what I''m up to! -- Check out my new startup: Server Monitoring as a Service @ http://tribily.com Follow @tribily on Twitter and/or ''Like'' our Facebook page at http://www.facebook.com/tribily -- 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-05 13:49 UTC
Re: [Puppet Users] helper define for looping through array
On 01/05/2012 02:45 PM, Walter Heck wrote:> I was afraid this was going to be the only solution. I guess we could > really do with more sane handling of arrays in puppet. This is a > workaround to make a workaround work..Humm, if you can find a sensible way to hash your data, you might be able to take advantage of create_resources(). -- 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.
jcbollinger
2012-Jan-06 15:43 UTC
[Puppet Users] Re: helper define for looping through array
On Jan 5, 7:45 am, Walter Heck <walterh...@gmail.com> wrote:> I was afraid this was going to be the only solution. I guess we could > really do with more sane handling of arrays in puppet. This is a > workaround to make a workaround work..Characterizing anything here as a workaround suggests that you are fighting against the tool. That is bound to leave you dissatisfied, and likely to lead you to commit the same kinds of errors again, which will make you even more dissatisfied. Definitions establish user-defined resource types. The resources of any given type must all have unique names. Puppet provides a short- cut mechanism, using arrays, for declaring multiple resources with the same properties but different names. This is all perfectly sensible. You are causing yourself problems by construing definitions to provide a looping construct. They do not. Puppet DSL does not have such a construct, thus you should discipline yourself to avoid thinking in such terms when you are writing Puppet manifests. Instead, be sure to write definitions that have some kind of inherent meaning and observable manifestation on the target node, and then, among other things, it will flow naturally that each instance gets a distinct title. If you cannot or do not wish to adapt to Puppet DSL''s declarative nature, then you can always write Ruby manifests instead. Here is how I might write it (a variant of Felix''s first suggestion), stripped to the essentials: define reprepro::repo::conf_override() { include ''reprepro::params'' $distro_and_name = split($name, '':'') $distribution = $distro_and_name[0] $override_name = $distro_and_name[1] file { "${reprepro::params::repo_base_dir}/${distribution}/conf/ override.${override_name}": ensure => "present" } } define reprepro::repo($distribution, $codenames) { reprepro::repo::conf_override { regsubst($codenames, /^/, "$ {distribution}:"): } } Some notes on that: 1) it is not necessary to copy the $codenames array prior to passing it to regsubst. Nothing changes a Puppet variable''s value once it is set, including Puppet functions. 2) Because definition ''reprepro::repo::conf_override'' uses a variable from class ''reprepro::params'', it should ''include'' that class, as shown, even if it seems safe to assume that that class will have already been included. 3) It would be possible, and perhaps slightly safer, to set the distribution name as a parameter to Reprepro::repo::conf_override, and then to use that to extract the "override_name". I chose instead to avoid duplication of information. 4) It might also be possible to interpolate the elements of array $distro_and_name directly into the file name instead of first assigning each to a scalar variable, but assigning the elements to their own variables serves better for self-documentation. John -- 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.