Hi puppeteers, In the function reference [1], I found a ''split'' function for splitting a string into an array, but not a ''join'' function for joining an array into a string. Why not? :) I have a list of IP addresses, that I use with ssh_authorized_key to restrict access. The list is now simply a comma-separated list in a string, but if I want to use the list for other purposes as well, I thought it might be better to store the list as an array and join() it with the proper glue whenever needed. What do you recommend? Best regards, Martijn. [1] http://docs.puppetlabs.com/references/stable/function.htm
----- "Martijn Grendelman" <martijn@grendelman.net> wrote:> Hi puppeteers, > > In the function reference [1], I found a ''split'' function for > splitting a > string into an array, but not a ''join'' function for joining an array > into > a string. Why not? :) > > I have a list of IP addresses, that I use with ssh_authorized_key to > restrict access. The list is now simply a comma-separated list in a > string, but if I want to use the list for other purposes as well, I > thought it might be better to store the list as an array and join() > it > with the proper glue whenever needed. > > What do you recommend?- you can write a join function and contribute it to the project, they are very easy to write - you can use something like $ips = inline_template("<%= ipaddress.split(/,/).join('' '') %>") or use regex or something like that. -- R.I.Pienaar -- 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.
On 09-09-10 11:50, R.I.Pienaar wrote:>> In the function reference [1], I found a ''split'' function for >> splitting a >> string into an array, but not a ''join'' function for joining an array >> into >> a string. Why not? :) >> >> I have a list of IP addresses, that I use with ssh_authorized_key to >> restrict access. The list is now simply a comma-separated list in a >> string, but if I want to use the list for other purposes as well, I >> thought it might be better to store the list as an array and join() >> it >> with the proper glue whenever needed. >> >> What do you recommend? > > - you can write a join function and contribute it to the project, they are very easy to writeI have added this function to my ''common'' module: puppet$ cat modules/common/lib/puppet/parser/functions/join.rb module Puppet::Parser::Functions newfunction(:join, :type => :rvalue) do |args| args[0].join(args[1]) end end I didn''t come up with it myself though, I found it on the web somewhere. Looking at the source for the ''split'' function, I guess the function needs documentation and maybe some error checking, like the number of arguments. How would I contribute something like this to the project?> - you can use something like $ips = inline_template("<%= ipaddress.split(/,/).join('' '') %>") > or use regex or something like that.Thanks! Martijn.
Hi Martijn, here is an outline of the steps required for submitting a patch. http://projects.reductivelabs.com/projects/puppet/wiki/Development_Development_Lifecycle an overview would be: * create a ticket (if one does not already exist) * fork reductivelabs puppet repo from github.com/reductivelabs * create local branch * create unit tests * commit changes * push to remote repo feel free to ask any further questions related to the process here, #puppet , or on puppet-dev@googlegroups.com -Dan On Thu, Sep 9, 2010 at 3:54 AM, Martijn Grendelman <martijn@grendelman.net>wrote:> On 09-09-10 11:50, R.I.Pienaar wrote: > >> In the function reference [1], I found a ''split'' function for > >> splitting a > >> string into an array, but not a ''join'' function for joining an array > >> into > >> a string. Why not? :) > >> > >> I have a list of IP addresses, that I use with ssh_authorized_key to > >> restrict access. The list is now simply a comma-separated list in a > >> string, but if I want to use the list for other purposes as well, I > >> thought it might be better to store the list as an array and join() > >> it > >> with the proper glue whenever needed. > >> > >> What do you recommend? > > > > - you can write a join function and contribute it to the project, they > are very easy to write > > I have added this function to my ''common'' module: > > puppet$ cat modules/common/lib/puppet/parser/functions/join.rb > module Puppet::Parser::Functions > newfunction(:join, :type => :rvalue) do |args| > args[0].join(args[1]) > end > end > > I didn''t come up with it myself though, I found it on the web somewhere. > Looking at the source for the ''split'' function, I guess the function needs > documentation and maybe some error checking, like the number of arguments. > > How would I contribute something like this to the project? > > > - you can use something like $ips = inline_template("<%> ipaddress.split(/,/).join('' '') %>") > > or use regex or something like that. > > Thanks! > > Martijn. > > > > >-- 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.