hudsterboy
2010-Nov-16 17:33 UTC
[Puppet Users] Can''t do a nested define. What are my options?
I''m trying to create a directory structure from 2 arrays. First array is the "outter", second is the "inner". For each "outter", I''d like to loop through each "inner". Below is sort of what I''m trying to do. In the real world, the $sys_name and $mounts vars will be parsed from yaml and will be dynamic. In the example I''ve created static arrays for simplicity. Please don''t critique the code. I know it won''t work and is the wrong way to do it. I just want to give an idea of what I''m trying to do. $sys_name = [''sys1'', ''sys2'', ''sys3'', ''sys4''] $mounts = [''home'', ''var'', ''usr'', ''duck'', ''goose''] File { owner => ''root'', group => ''root'', mode => ''0755'', ensure => directory } define outter () { file { "/mnt/$sys_name": } define inner () { file {"$mount_base/$mounts":} } inner { $mounts } } outter { $sys_name: } So basically create directories from a dynamic array inside directories created from a dynamic array. Any way to do this in a simple way? -- 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.
Dan Bode
2010-Nov-16 17:45 UTC
Re: [Puppet Users] Can''t do a nested define. What are my options?
Hi Andrew, On Tue, Nov 16, 2010 at 9:33 AM, hudsterboy <andrewmorone@yahoo.com> wrote:> I''m trying to create a directory structure from 2 arrays. First array > is the "outter", second is the "inner". For each "outter", I''d like to > loop through each "inner". > > Below is sort of what I''m trying to do. In the real world, the > $sys_name and $mounts vars will be parsed from yaml and will be > dynamic. In the example I''ve created static arrays for simplicity. > > Please don''t critique the code. I know it won''t work and is the wrong > way to do it. I just want to give an idea of what I''m trying to do. > > $sys_name = [''sys1'', ''sys2'', ''sys3'', ''sys4''] > $mounts = [''home'', ''var'', ''usr'', ''duck'', ''goose''] > > File { owner => ''root'', group => ''root'', mode => ''0755'', ensure => > directory } > > define outter () { > file { "/mnt/$sys_name": } > > define inner () { > file {"$mount_base/$mounts":} > } > inner { $mounts } > > } > outter { $sys_name: } >Looping/iteration is somewhat difficult using Puppet''s DSL. Perhaps you should consider writing this manifest using the new Ruby DSL (available in 2.6.x) . I recently wrote a blog about it (which I believe is the most up to date documentation not counting the commit message): http://www.puppetlabs.com/blog/ruby-dsl/ its fairly bleeding edge, so feel free to ask questions. -Dan> So basically create directories from a dynamic array inside > directories created from a dynamic array. > Any way to do this in a simple way? > > -- > 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<puppet-users%2Bunsubscribe@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.
hudsterboy
2010-Nov-16 22:44 UTC
[Puppet Users] Re: Can''t do a nested define. What are my options?
Thanks Dan, Unfortunately, I don''t think we''re going to 2.6 any time soon in our environment. I was hoping there was something simpler and I was just being dumb. Good news is, maybe I''m not so dumb! lol. I''m looking at using a custom function a co-worker wrote that might help. If it works well, I''ll ask him to post it up here. I can see that it might be useful. Drew On Nov 16, 12:45 pm, Dan Bode <d...@puppetlabs.com> wrote:> Hi Andrew, > > > > On Tue, Nov 16, 2010 at 9:33 AM, hudsterboy <andrewmor...@yahoo.com> wrote: > > I''m trying to create a directory structure from 2 arrays. First array > > is the "outter", second is the "inner". For each "outter", I''d like to > > loop through each "inner". > > > Below is sort of what I''m trying to do. In the real world, the > > $sys_name and $mounts vars will be parsed from yaml and will be > > dynamic. In the example I''ve created static arrays for simplicity. > > > Please don''t critique the code. I know it won''t work and is the wrong > > way to do it. I just want to give an idea of what I''m trying to do. > > > $sys_name = [''sys1'', ''sys2'', ''sys3'', ''sys4''] > > $mounts = [''home'', ''var'', ''usr'', ''duck'', ''goose''] > > > File { owner => ''root'', group => ''root'', mode => ''0755'', ensure => > > directory } > > > define outter () { > > file { "/mnt/$sys_name": } > > > define inner () { > > file {"$mount_base/$mounts":} > > } > > inner { $mounts } > > > } > > outter { $sys_name: } > > Looping/iteration is somewhat difficult using Puppet''s DSL. > > Perhaps you should consider writing this manifest using the new Ruby DSL > (available in 2.6.x) . I recently wrote a blog about it (which I believe is > the most up to date documentation not counting the commit message): > > http://www.puppetlabs.com/blog/ruby-dsl/ > > its fairly bleeding edge, so feel free to ask questions. > > -Dan > > > So basically create directories from a dynamic array inside > > directories created from a dynamic array. > > Any way to do this in a simple way? > > > -- > > 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<puppet-users%2Bunsubscribe@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.
Felix Frank
2010-Nov-19 17:49 UTC
Re: [Puppet Users] Can''t do a nested define. What are my options?
Hi, define sysdir($dirs) { define subdir($base) { file { "$base/$name": ensure => directory } } file { "/mnt/$name": ensure => directory } suddir { $dirs: base => "/mnt/$name" } } sysdir { $sys_name: dirs => $mounts } Haven''t tested it, but something like this should work. Little convoluted, though, but your requirements are not easy to meet. Cheers, Felix On 11/16/2010 06:33 PM, hudsterboy wrote:> I''m trying to create a directory structure from 2 arrays. First array > is the "outter", second is the "inner". For each "outter", I''d like to > loop through each "inner". > > Below is sort of what I''m trying to do. In the real world, the > $sys_name and $mounts vars will be parsed from yaml and will be > dynamic. In the example I''ve created static arrays for simplicity. > > Please don''t critique the code. I know it won''t work and is the wrong > way to do it. I just want to give an idea of what I''m trying to do. > > $sys_name = [''sys1'', ''sys2'', ''sys3'', ''sys4''] > $mounts = [''home'', ''var'', ''usr'', ''duck'', ''goose''] > > File { owner => ''root'', group => ''root'', mode => ''0755'', ensure => > directory } > > define outter () { > file { "/mnt/$sys_name": } > > define inner () { > file {"$mount_base/$mounts":} > } > inner { $mounts } > > } > outter { $sys_name: } > > So basically create directories from a dynamic array inside > directories created from a dynamic array. > Any way to do this in a simple way? >-- 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.