On Sep 27, 11:15 am, Marc Richman <marc.rich...@livewiremobile.com> wrote: > I am trying to use a hash to mount a bunch of directories but I am unsure how > to get the value for the key. Feel free to tell me I am going about this the > wrong way. > > This is the error I get from my module (init.pp listed below): > > Could not retrieve catalog from remote server: Error 400 on SERVER: value is > a required option for Puppet::Parser::Resource::Param at > /etc/puppet/modules/sandbox/mount-content-new/manifests/init.pp:27 on node > bos-test01.contentstore.net > > Obviously I don't know how to refer to the inside the mount type > > ----------------- init.pp ------------------------------------------------- > > # > > # $Id:$ > > # > > class mount-content-new { > > $content = { > > '/content/music/beggars' => 'bos-netapp01:/vol/Indy_1/beggars', > > '/content/music/bmg' => 'bos-netapp02:/vol/bmg/bmg' > > } > > $keys = split(inline_template("<%= content.keys.join(',') %>"), ",") > > file {["/content","/content/music"]: > > ensure => directory, > > owner => root, > > group => root, > > mode => 0755, > > } > > file {$keys: > > ensure => directory, > > mode => 0755, > > } > > mount {$keys: > > atboot => true, > > device => $content[$keys], > > ensure => "mounted", > > fstype => "nfs", > > options => > "rw,bg,hard,intr,rsize=32768,wsize=32768,vers=3,proto=tcp,timeo=600,retrans=2", > > dump => "0", > > pass => "1" > > } > > }
The short answer to your question is that you can wrap the Mount resource declaration in a define, and therein use the $name variable: mount_content { $keys: content_table => $content } define mount_content($content_table) { mount {$name: atboot => true, device => $content_table[$name], ensure => "mounted", fstype => "nfs", options => "rw,bg,hard,intr,rsize=32768,wsize=32768,vers=3,proto=tcp,timeo=600,retrans=2", dump => "0", pass => "1" } } A somewhat cleaner answer, in that it does not require manually extracting the hash keys (or even values), would be to use the create_resources() function, something like this: class mount_content_new { $content = { '/content/music/beggars' => { device => 'bos-netapp01:/vol/Indy_1/ beggars' }, '/content/music/bmg' => { device => 'bos-netapp02:/vol/bmg/ bmg' } } define mount_one_content ($device) { file {$name: ensure => directory, mode => 0755, } mount {$name: atboot => true, device => $device, ensure => "mounted", fstype => "nfs", options => "rw,bg,hard,intr,rsize=32768,wsize=32768,vers=3,proto=tcp,timeo=600,retrans=2", dump => "0", pass => "1" } } file {["/content","/content/music"]: ensure => directory, owner => root, group => root, mode => 0755, } create_resources("mount_one_content", $content) } Note the different structure of the $content hash (values are now hashes), and the correspondence of the keys of the inner hashes with the parameters of the 'mount_one_content' definition. John -- 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.