I have an array: $nodes = [''gfs01'' ,''gfs02'', ''gfs03'', ''gfs04] and a string variable: $brick_store = "/var/bricks" How can I append "/var/bricks" to each item in the array? Lack of a looping construct makes this challenging in puppet. Such that: brick_array = [''gfs01:/var/bricks'', ''gfs02:/var/bricks'', ... ] I also need to come up with a way to append a further sequence of incrementing brick numbers to the items as well. Doug -- 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.
Try using regsubst: http://docs.puppetlabs.com/references/stable/function.html#regsubst On Mon, Aug 27, 2012 at 3:03 PM, Douglas Garstang <doug.garstang@gmail.com> wrote:> I have an array: > > $nodes = [''gfs01'' ,''gfs02'', ''gfs03'', ''gfs04] > > and a string variable: > > $brick_store = "/var/bricks" > > How can I append "/var/bricks" to each item in the array? Lack of a > looping construct makes this challenging in puppet. > > Such that: > > brick_array = [''gfs01:/var/bricks'', ''gfs02:/var/bricks'', ... ] > > I also need to come up with a way to append a further sequence of > incrementing brick numbers to the items as well. > > Doug > > -- > 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. >-- Trevor Vaughan Vice President, Onyx Point, Inc (410) 541-6699 tvaughan@onyxpoint.com -- This account not approved for unencrypted proprietary information -- -- 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.
Trevor, Thanks. I''m getting ''bad target Array'' with: define glusterfs::volume_create ( $brick_store, $nodes, $replicas=''1'', $transport=''tcp'' ) { ..... $n2 = regsubst ($nodes, ''$'', ":$brick_store") # Bad target array here. notice ("bricks = $n2") } On entering the define, $nodes = [''gfs01.us1.xxx.com'', ''gfs02.us1.xxx.com''] and $brick_store="/var/bricks" Doug. On Mon, Aug 27, 2012 at 12:44 PM, Trevor Vaughan <tvaughan@onyxpoint.com> wrote:> Try using regsubst: > http://docs.puppetlabs.com/references/stable/function.html#regsubst > > On Mon, Aug 27, 2012 at 3:03 PM, Douglas Garstang > <doug.garstang@gmail.com> wrote: >> I have an array: >> >> $nodes = [''gfs01'' ,''gfs02'', ''gfs03'', ''gfs04] >> >> and a string variable: >> >> $brick_store = "/var/bricks" >> >> How can I append "/var/bricks" to each item in the array? Lack of a >> looping construct makes this challenging in puppet. >> >> Such that: >> >> brick_array = [''gfs01:/var/bricks'', ''gfs02:/var/bricks'', ... ] >> >> I also need to come up with a way to append a further sequence of >> incrementing brick numbers to the items as well. >> >> Doug >> >> -- >> 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. >> > > > > -- > Trevor Vaughan > Vice President, Onyx Point, Inc > (410) 541-6699 > tvaughan@onyxpoint.com > > -- This account not approved for unencrypted proprietary information -- > > -- > 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. >-- Regards, Douglas Garstang http://www.linkedin.com/in/garstang Email: doug.garstang@gmail.com Cell: +1-805-340-5627 -- 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 could give inline_template() from stdlib a try instead. You could do: $nodes = [''gfs01'' ,''gfs02'', ''gfs03'', ''gfs04] $brick_store = "/var/bricks" $new = inline_template(''nodes.each {|n| etc etc etc'') I''m not 100% sure it''ll work in this case but I''ve done other similar evil things with inline_template. On Mon, Aug 27, 2012 at 4:06 PM, Douglas Garstang <doug.garstang@gmail.com> wrote:> Trevor, > > Thanks. I''m getting ''bad target Array'' with: > > define glusterfs::volume_create ( $brick_store, $nodes, $replicas=''1'', > $transport=''tcp'' ) { > ..... > > $n2 = regsubst ($nodes, ''$'', ":$brick_store") # Bad target array here. > notice ("bricks = $n2") > } > > On entering the define, $nodes = [''gfs01.us1.xxx.com'', > ''gfs02.us1.xxx.com''] and $brick_store="/var/bricks" > > Doug. > > On Mon, Aug 27, 2012 at 12:44 PM, Trevor Vaughan <tvaughan@onyxpoint.com> wrote: >> Try using regsubst: >> http://docs.puppetlabs.com/references/stable/function.html#regsubst >> >> On Mon, Aug 27, 2012 at 3:03 PM, Douglas Garstang >> <doug.garstang@gmail.com> wrote: >>> I have an array: >>> >>> $nodes = [''gfs01'' ,''gfs02'', ''gfs03'', ''gfs04] >>> >>> and a string variable: >>> >>> $brick_store = "/var/bricks" >>> >>> How can I append "/var/bricks" to each item in the array? Lack of a >>> looping construct makes this challenging in puppet. >>> >>> Such that: >>> >>> brick_array = [''gfs01:/var/bricks'', ''gfs02:/var/bricks'', ... ] >>> >>> I also need to come up with a way to append a further sequence of >>> incrementing brick numbers to the items as well. >>> >>> Doug >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Trevor Vaughan >> Vice President, Onyx Point, Inc >> (410) 541-6699 >> tvaughan@onyxpoint.com >> >> -- This account not approved for unencrypted proprietary information -- >> >> -- >> 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. >> > > > > -- > Regards, > > Douglas Garstang > http://www.linkedin.com/in/garstang > Email: doug.garstang@gmail.com > Cell: +1-805-340-5627 > > -- > 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.
On Monday, August 27, 2012 3:06:30 PM UTC-5, Douglas wrote:> > Trevor, > > Thanks. I''m getting ''bad target Array'' with: > > define glusterfs::volume_create ( $brick_store, $nodes, $replicas=''1'', > $transport=''tcp'' ) { > ..... > > $n2 = regsubst ($nodes, ''$'', ":$brick_store") # Bad target array here. > notice ("bricks = $n2") > } > > On entering the define, $nodes = [''gfs01.us1.xxx.com'', > ''gfs02.us1.xxx.com''] and $brick_store="/var/bricks" >I think I would have expected that to work as written, but perhaps Ruby objects to the pattern having only an anchor. What about this: $n2 = regsubst ($nodes, ''^(.*)$'', "\1:$brick_store") John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/44ZecAxY-nYJ. 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.
Krzysztof Wilczynski
2012-Aug-28 10:24 UTC
[Puppet Users] Re: Append string to list items.
Hi, You could try this: matti@acrux ~ $ cat | puppet apply --noop notice bracket_expansion(''gfs[01-10]:/var/bricks'') notice: Scope(Class[main]): gfs01:/var/bricks gfs02:/var/bricks gfs03:/var/bricks gfs04:/var/bricks gfs05:/var/bricks gfs06:/var/bricks gfs07:/var/bricks gfs08:/var/bricks gfs09:/var/bricks gfs10:/var/bricks notice: Finished catalog run in 0.11 seconds Not quite a loop, but will do the trick (and handles zero-padding). https://github.com/kwilczynski/puppet-functions/blob/master/lib/puppet/parser/functions/bracket_expansion.rb I will look into adding array-walking mode to join, prefix and join_with_prefix. KW On Monday, 27 August 2012 20:03:57 UTC+1, Douglas wrote:> > I have an array: > > $nodes = [''gfs01'' ,''gfs02'', ''gfs03'', ''gfs04] > > and a string variable: > > $brick_store = "/var/bricks" > > How can I append "/var/bricks" to each item in the array? Lack of a > looping construct makes this challenging in puppet. > > Such that: > > brick_array = [''gfs01:/var/bricks'', ''gfs02:/var/bricks'', ... ] > > I also need to come up with a way to append a further sequence of > incrementing brick numbers to the items as well. > > Doug >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/yNayGxbkAjgJ. 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.