Sorry about that, google hotkeys (Grrr) Hi folks, I think i''m missing something obvious here. I''m trying to search/replace multiple times for n files but I keep hitting a ''ArgumentError: Duplicate definition'' or similar. I guess this is because i''m using ${name} to for the multiple files, but as far as I can tell, i''m unable to use another type of array. i.e. if I do: $name = ["file1", "file2", etc.. ] define replacetext ($cwd, $stext, $rtext, $sstext, $rrtext) { exec {$name: cwd => $cwd, path => ["/bin"], command => "sed -i ''s/$stext/$rtext/'' ./${name}", } exec {$name: cwd => $cwd, path => ["/bin"], command => "sed -i ''s/$sstext/$rrtext/'' ./${name}", } } replacetext { $myfiles: cwd => "/opt", stext => "replacethis", rtext => "withthis", sstext => "replacethis2", rrtext => "withthis2", } It throws a Duplicate definition error. If I take out one the exec calls it works fine on each of the files. I tried giving it another array of the files so I could do: $files = ["file1", "file2", etc.. ] define searchreplace ($cwd, $stext, $rtext, $sstext, $rrtext, $files) { exec {"1": cwd => $cwd, path => ["/bin"], command => "sed -i ''s/$stext/$rtext/'' ./${files}", } exec {"2": cwd => $cwd, path => ["/bin"], command => "sed -i ''s/$stext/$rtext/'' ./${files}", } } But that executed the sed command with all of the files as input. I also tried with a general define searchreplace method but i''m only able to call it once in a class with the $name due to the $name method again. Is it possible to get puppet to iterate a definition other than using the $name method? Thanks, Matt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Meier
2008-Oct-13 12:06 UTC
[Puppet Users] Re: Calling a define multiple times - full
Hi> But that executed the sed command with all of the files as input. > > I also tried with a general define searchreplace method but i''m only able to > call it once in a class with the $name due to the $name method again. > > Is it possible to get puppet to iterate a definition other than using the > $name method?use something else than $name as filename. because $name have to be unique. greets pete --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Pete, I tried that with $myfiles as an array, but as I said, that just executed the sed command with all of the filenames concatanated. I''ve got a fix at the moment. I''ve just prefixed multiple execs in the define method with something unique. Its working, but just feels like there would be a better way to do this. My code at the moment is: define searchreplace ( $cwd, $stext, $rtext, $sstext, $rrtext, $ssstext, $rrrtext ) { exec {"dns_$name": cwd => $cwd, path => ["/bin"], command => "sed -i ''s/$stext/$rtext/'' ./${name}", } exec {"tag_$name": cwd => $cwd, path => ["/bin"], command => "sed -i ''s/$sstext/$rrtext/'' ./${name}", } exec {"ray_$name": cwd => $cwd, path => ["/bin"], command => "sed -i ''s/$ssstext/$rrrtext/'' ./${name}", } } searchreplace {$bfprocesses : cwd => "/home", stext => "replacethis", rtext => $dns, sstext => "replacethis2", rrtext => $tag, ssstext => "replacethis3", rrrtext => $ray, } } It works - just wondering if there was a simpler way. Cheers, Matt 2008/10/13 Peter Meier <peter.meier@immerda.ch>> > Hi > > > But that executed the sed command with all of the files as input. > > > > I also tried with a general define searchreplace method but i''m only able > to > > call it once in a class with the $name due to the $name method again. > > > > Is it possible to get puppet to iterate a definition other than using the > > $name method? > > > use something else than $name as filename. because $name have to be unique. > > greets pete > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paul Lathrop
2008-Oct-14 16:47 UTC
[Puppet Users] Re: Calling a define multiple times - full
Matt, From the terminology you are using, you seem to have fallen into the trap of thinking of defines as functions which you call. I highly recommend you avoid this; it leads you to certain mistaken assumptions about how defines work. From your description I am having difficulty understanding what you are trying to accomplish. Can you provide some specific details? You are trying to perform a search/replace on multiple files in a single resource? With those questions answered I might be able to help. --Paul On Mon, Oct 13, 2008 at 5:17 AM, Matt <mattmoran76@gmail.com> wrote:> Hi Pete, > > I tried that with $myfiles as an array, but as I said, that just executed > the sed command with all of the filenames concatanated. > > I''ve got a fix at the moment. I''ve just prefixed multiple execs in the > define method with something unique. Its working, but just feels like there > would be a better way to do this. > > My code at the moment is: > > define searchreplace ( $cwd, $stext, $rtext, $sstext, $rrtext, $ssstext, > $rrrtext ) { > exec {"dns_$name": > cwd => $cwd, > path => ["/bin"], > command => "sed -i ''s/$stext/$rtext/'' ./${name}", > } > exec {"tag_$name": > cwd => $cwd, > path => ["/bin"], > command => "sed -i ''s/$sstext/$rrtext/'' ./${name}", > } > exec {"ray_$name": > cwd => $cwd, > path => ["/bin"], > command => "sed -i ''s/$ssstext/$rrrtext/'' ./${name}", > } > } > > searchreplace {$bfprocesses : > cwd => "/home", > stext => "replacethis", > rtext => $dns, > sstext => "replacethis2", > rrtext => $tag, > ssstext => "replacethis3", > rrrtext => $ray, > > } > } > > > It works - just wondering if there was a simpler way. > > Cheers, > > Matt > > 2008/10/13 Peter Meier <peter.meier@immerda.ch> >> >> Hi >> >> > But that executed the sed command with all of the files as input. >> > >> > I also tried with a general define searchreplace method but i''m only >> > able to >> > call it once in a class with the $name due to the $name method again. >> > >> > Is it possible to get puppet to iterate a definition other than using >> > the >> > $name method? >> >> >> use something else than $name as filename. because $name have to be >> unique. >> >> greets pete >> >> > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paul, You''re correct, I did indeed fall in to thinking that defines act similar to functions. I wanted to create a generic definition that basically did a linux ''sed'', but the only way I could do it with an array of files was by using the $name array. I was having issues with this as I had multiple execs in the define, but i''d just called them exec { "$name... So that was my issue. I''m a bit blurred on when puppet iterates through an array and when it concatanates the array. Does it only iterate through $name on defines? Thanks, Matt 2008/10/14 Paul Lathrop <paul@tertiusfamily.net>> > Matt, > > From the terminology you are using, you seem to have fallen into the > trap of thinking of defines as functions which you call. I highly > recommend you avoid this; it leads you to certain mistaken assumptions > about how defines work. > > From your description I am having difficulty understanding what you > are trying to accomplish. Can you provide some specific details? You > are trying to perform a search/replace on multiple files in a single > resource? > > With those questions answered I might be able to help. > > --Paul > > On Mon, Oct 13, 2008 at 5:17 AM, Matt <mattmoran76@gmail.com> wrote: > > Hi Pete, > > > > I tried that with $myfiles as an array, but as I said, that just executed > > the sed command with all of the filenames concatanated. > > > > I''ve got a fix at the moment. I''ve just prefixed multiple execs in the > > define method with something unique. Its working, but just feels like > there > > would be a better way to do this. > > > > My code at the moment is: > > > > define searchreplace ( $cwd, $stext, $rtext, $sstext, $rrtext, $ssstext, > > $rrrtext ) { > > exec {"dns_$name": > > cwd => $cwd, > > path => ["/bin"], > > command => "sed -i ''s/$stext/$rtext/'' ./${name}", > > } > > exec {"tag_$name": > > cwd => $cwd, > > path => ["/bin"], > > command => "sed -i ''s/$sstext/$rrtext/'' ./${name}", > > } > > exec {"ray_$name": > > cwd => $cwd, > > path => ["/bin"], > > command => "sed -i ''s/$ssstext/$rrrtext/'' ./${name}", > > } > > } > > > > searchreplace {$bfprocesses : > > cwd => "/home", > > stext => "replacethis", > > rtext => $dns, > > sstext => "replacethis2", > > rrtext => $tag, > > ssstext => "replacethis3", > > rrrtext => $ray, > > > > } > > } > > > > > > It works - just wondering if there was a simpler way. > > > > Cheers, > > > > Matt > > > > 2008/10/13 Peter Meier <peter.meier@immerda.ch> > >> > >> Hi > >> > >> > But that executed the sed command with all of the files as input. > >> > > >> > I also tried with a general define searchreplace method but i''m only > >> > able to > >> > call it once in a class with the $name due to the $name method again. > >> > > >> > Is it possible to get puppet to iterate a definition other than using > >> > the > >> > $name method? > >> > >> > >> use something else than $name as filename. because $name have to be > >> unique. > >> > >> greets pete > >> > >> > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Evan Hisey
2008-Oct-15 15:44 UTC
[Puppet Users] Re: Calling a define multiple times - full
On Mon, Oct 13, 2008 at 7:17 AM, Matt <mattmoran76@gmail.com> wrote:> Hi Pete, > > I tried that with $myfiles as an array, but as I said, that just executed > the sed command with all of the filenames concatanated. > > I''ve got a fix at the moment. I''ve just prefixed multiple execs in the > define method with something unique. Its working, but just feels like there > would be a better way to do this. > > My code at the moment is: > > define searchreplace ( $cwd, $stext, $rtext, $sstext, $rrtext, $ssstext, > $rrrtext ) { > exec {"dns_$name": > cwd => $cwd, > path => ["/bin"], > command => "sed -i ''s/$stext/$rtext/'' ./${name}", > } > exec {"tag_$name": > cwd => $cwd, > path => ["/bin"], > command => "sed -i ''s/$sstext/$rrtext/'' ./${name}", > } > exec {"ray_$name": > cwd => $cwd, > path => ["/bin"], > command => "sed -i ''s/$ssstext/$rrrtext/'' ./${name}", > } > } > > searchreplace {$bfprocesses : > cwd => "/home", > stext => "replacethis", > rtext => $dns, > sstext => "replacethis2", > rrtext => $tag, > ssstext => "replacethis3", > rrrtext => $ray, > > } > } > > > It works - just wondering if there was a simpler way. >Have you looked at teh simple text edit examples in the wiki? http://reductivelabs.com/trac/puppet/wiki/Recipes/SimpleText , It has several examples of how to do text edits and suggestions for improvement. Evan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---