How do you dynamically create classes? 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). 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? 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. Thanks. -eric -- 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.
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-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.
Eric Snow <esnow@verio.net> writes:> How do you dynamically create classes?You pretty much can''t: puppet is aimed at being a deterministic system, and so it wants to have a non-programmatic state to achieve.[1]> 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).The conventional way would be this: define my::user () { user { $name: whatever => ''foo'' } } my::user { ["one", "two", "red", "blue"]: } Puppet will create all those resources nicely. [...]> 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 strongly suspect that a worked example of what you want to do, but that is failing, would help make the whole thing a lot clearer... Anyhow, my final bit of (now unsolicited) advice here: Don''t do that anyhow. Use LDAP, or some other network directory service, to manage your user accounts. It hurts way less than trying to do this at scale, once you start to discover needs for things like consistent UIDs, etc. Regards, Daniel Footnotes: [1] Like the English language, puppet isn''t that pure, and you can work around this in a whole bunch of ways. Pure-ruby manifests in 2.6 might be a way to do that, for example. -- ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707 ♽ made with 100 percent post-consumer electrons -- 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.
On Fri, Nov 12, 2010 at 09:32:16AM +1100, Daniel Pittman wrote:> Footnotes: > [1] Like the English language, puppet isn''t that pure, and you can work > around this in a whole bunch of ways. Pure-ruby manifests in 2.6 might > be a way to do that, for example.Oh, I knew somebody was going to say that. I don''t much like the idea of ruby manifests; it seems to turn Puppet''s design upside down. I try to reduce the direct use of Ruby in my puppet configurations to an absolute minimum. -- Bruce It is impolite to tell a man who is carrying you on his shoulders that his head smells. -- 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.
Thanks. On Nov 11, 3:21 pm, Bruce Richardson <itsbr...@workshy.org> wrote:> 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-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.
Bruce Richardson <itsbruce@workshy.org> writes:> On Thu, Nov 11, 2010 at 12:50:02PM -0800, Eric Snow wrote:[...]> 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 propertiesIt really wouldn''t be a terribly hard extension to write one, however. :) Daniel -- ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707 ♽ made with 100 percent post-consumer electrons -- 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.
On Nov 11, 2:21 pm, Bruce Richardson <itsbr...@workshy.org> wrote:> (I wish Luke had chosen a name other than "class" for Puppet''s > classes; it only confuses people).Wondering off topic, but my favorite alternate term so far is "containers". Doesn''t confuse people with programming backgrounds as much. Also implies that they''re singletons, to me at least. And I think we''re getting to a point in the DSL where the difference between definitions and classes is just the singleton aspect. -- 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.