On Thu, Nov 11, 2010 at 12:50:02PM -0800, Eric Snow wrote: > How do you dynamically create classes?
You don't. 2.6 has parameterized classes but that's not quite what you mean. > > For instance, I have a bunch of users to make. I have all their > usernames. Each is the same as the others except for the username and > one other value. I don't want to have to spell out a User for each, > but would rather set up them up dynamically, in a much cleaner way > (and more maintainable). You can use resource defaults to take out most of the drudgery User { managed => true, shell = '/bin/bash' } Then you only need type out the varying properties of each user. > > It looks like parameterized classes would mostly do it, but is the > syntax for including a parameterized class the same everywhere? Can a > parameterized class be virtual? No. Resources can be virtual but not classes. If you were hoping to be able to create all of these users by iterating through a hash, or something similar, then Puppet really doesn't support that. Puppet's DSL is declaritive and can't be treated like some OO language (I wish Luke had chosen a name other than "class" for Puppet's classes; it only confuses people). Have you noticed that Puppet has arrays and hashes but doesn't have a keys() function? You *could* have a hash of users and their properties $users = { john => { shell => '/bin/bash', uid => '501' }, david => { shell => '/bin/tcsh', uid = '501' } and have a define which consulted that hash, as in define hash_user ( $user_hash ) { user { $name: ensure => 'present', managed => true, shell => $users[$name][shell], uid => $user_hash[$name][uid] } } But since there is no keys function, you can't do hash_user { [ keys($users) ]: user_hash => $users } You have to do hash_user { [ 'john', 'david' ]: user_hash => $users } which isn't really saving you a lot. Bluntly, Puppet wants you to declare your resources explicitly. > As well, I was hoping to set up some defines in the dynamically > created user so that they could be used from the class's namespace. > The alternative is to do them separately and pass in the same > information that I already passed in to the class, which seems messier > than just providing them from the class's namespace. I think there may be a misplaced word in there; it doesn't seem to make entire sense. -- Bruce Get thee behind me, Stan: for it is written, thou hast gotten me into another fine mess. -- Oliver 4:8 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@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.