1

I have two file

class hadoopfile::file {

$diskname  = [aaa,bbb,ccc,ddd,eee,']

$filename  = [02,03,04,05,06]

hadoopfile::diskcreate_def { '$diskname:','$filename:' }
#hadoopfile::diskcreate_def { $filename: }
}



 define hadoopfile::diskcreate_def (
  $diskname,$filename = $title)
  {
  physical_volume {["/dev/$diskname"]:
    ensure  => present,
  }

  file { 'opt/db/$filename':
    ensure  => directory,
  }

  mount { filemount:
    ensure  => mounted,
    name    => "opt/db/$filename",
    fstype  => 'ext4',
    options => 'defaults',
    atboot  => true,
    dump    => '1',
    pass    => '2',
    require => File["/opt/hd/db/data/$filename"]
    }
   }

when I compile the above I got

Syntax error at '}'; expected '}' at /etc/hadoopfile/manifests/file.pp:15 on node My doubt is, can we create pass two variable in define.

Olive
  • 25
  • 2
  • 5

2 Answers2

0

Try to remove the single-quote ' from the first array definition. That should make it compile.

$diskname  = [aaa,bbb,ccc,ddd,eee]

Then, according to the documentation, it is possible to pass a list of parameters to a class, or a defined type. Use this to reference your defined type

hadoopfile::diskcreate_def { "${diskname}":, "${filename}": }
  • In the declaration, you would 1. need to remove the double quotes and 2. use a semicolon `;` instead of comma `,` - but I don't think this is what the OP wants, anyway. – Felix Frank Nov 17 '14 at 17:48
0

It would appear that you are looking for a mapping drivename to filename. Mappings are not expressed by pairs of arrays - they are represented by hashes.

$disks = {
    '02' => { diskname => 'aaa', },
    '03' => { diskname => 'bbb', },
    '04' => { diskname => 'ccc', },
    '05' => { diskname => 'ddd', },
    '06' => { diskname => 'eee', },
}

You can translate this into resources through the create_resources function.

create_resources('hadoopfile::diskcreate_def', $disks)

Each key in your hash becomes a resource title, and the value hash holds the attribute/value pairs.

General remark: Do not name your defines in this fashion. The define name should be descriptive of what each resource represents on your systems, such as hadoopfile::mounted_volume.

Felix Frank
  • 3,093
  • 1
  • 16
  • 22