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 post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.