FWIW, there is a join function in stdlib.

https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/lib/puppet/parser/functions/join.rb

Mark

On Saturday, August 11, 2012 8:21:05 AM UTC-4, Stefan Schulte wrote:
>
> On Fri, Aug 10, 2012 at 05:10:20PM -0700, Douglas Garstang wrote: 
> > How can I pass an array to a define? It's not documented in the puppet 
> > language guide. 
> > 
> > I've got: 
> > 
> > define lvm::create_vg ( $pvdisks ) { 
> >     exec { 
> >         'pvcreate': 
> >             command => "/sbin/pvcreate -yf $pvdisks", 
> >             unless  => "/sbin/pvdisplay $pvdisks", 
> >            ... 
> >     } 
> > } 
> > 
> > class someclass { 
> >     lvm::create_vg { 
> >         'bcvg01': 
> >             pvdisks => ['/dev/xvdb1', '/dev/xvdc1']; 
> >     } 
> > } 
> > 
> > Inside the define, $pvdisks gets expanded to '/dev/xvdb1/dev/xvdc1' 
> > 
> > Doug. 
>
> Inside your define $pvdisks is whatever you passed as the pvdisks 
> parameter, so in your case $pvdisks *is* an array. But in the unless 
> parameter you use the array in a string context so all your items are 
> concatenated. Unfortunately puppet does not have a join function to 
> convert an array to a string. 
>
> On the other hand it may not be desired to destroy every disk you pass 
> as in the pvdisks array if only one of the disks is not a LVM disk (as 
> pvdisplay returns with a non-zero exitcode as soon as one disk is not 
> recognized to be a LVM disk) 
>
> So the best approach is probably to get the LVM puppet plugin and 
> replace your exec with 
>
>     physical_volume { $pvdisks: 
>       ensure => present, 
>     } 
>
> The physical_volume is a new type that comes with the LVM plugin. 
>
> [1] http://forge.puppetlabs.com/puppetlabs/lvm 
>
> -Stefan 
>
>

-- 
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/-/BPHP-2vn1FUJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to