lists@truthisfreedom.org.uk
2010-Sep-06 16:36 UTC
[Puppet Users] for each in puppet templates
Hi all, I''m sure there''s an easy way to do this, however I can''t work it out! I''ve got a custom fact named "mysql_repl_dbs" and is has the databases that a host needs to replicate as a comma separated list. I want my template for my.cnf to add a replicate-do-db= statement for each of these values, however when ever I try the following: <% mysql_repl_dbs.split['',''].each do | dbname | -%> replicate-do-db=<%=dbname%> <% end -%> I get an error stating that puppet cannot convert a String to an Integer. There must be a way to do this, but I''m tearing my hair out here! Thanks in advance, 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.
lists@truthisfreedom.org.uk wrote:> <% mysql_repl_dbs.split['',''].each do | dbname | -%> > replicate-do-db=<%=dbname%> > <% end -%> > > I get an error stating that puppet cannot convert a String to an Integer.Function calls in Ruby use round parenthesis or none at all, not square parenthesis. Square parenthesis are used for indexing. Your code means: call the ''split'' method on mysql_repl_dbs with no parameters, and then index the result with the string '',''. The split method will return an array of strings (and since you didn''t pass any parameters to split, it will probably only be one element long, that element being the original string you tried to split). And arrays can only be indexed by integers. What you want is "mysql_repl_dbs.split('','').each() do". /Bellman -- 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.
Matthew Macdonald-Wallace
2010-Sep-06 20:17 UTC
Re: [Puppet Users] for each in puppet templates
Doh! I knew it would be something obvious. Thanks M. On 6 Sep 2010 20:55, "Thomas Bellman" <bellman@nsc.liu.se> wrote: lists@truthisfreedom.org.uk wrote:> <% mysql_repl_dbs.split['',''].each do | dbname | -%> > replicat...Function calls in Ruby use round parenthesis or none at all, not square parenthesis. Square parenthesis are used for indexing. Your code means: call the ''split'' method on mysql_repl_dbs with no parameters, and then index the result with the string '',''. The split method will return an array of strings (and since you didn''t pass any parameters to split, it will probably only be one element long, that element being the original string you tried to split). And arrays can only be indexed by integers. What you want is "mysql_repl_dbs.split('','').each() do". /Bellman -- You received this message because you are subscribed to the Google Groups "Puppet Users" group... -- 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.