beamin melbin
2011-Nov-29 21:01 UTC
[Puppet Users] How do I require a resource in a definition based on an array parameter?
I have a define that looks like this: define user::sys_user($fullname, $uid, $groups, $shell=''/bin/bash'', $authkey, $authkey_type=rsa) { $username = "sys_${name}" group { $username: gid => $uid, } user { $username: require => Group[$username], ensure => present, uid => $uid, gid => $uid, groups => $groups, comment => $fullname, shell => $shell, managehome => true, allowdupe => false, } ssh_authorized_key { "${username}_authkey": user => $username, ensure => present, key => $authkey, type => $authkey_type, } } In the user resource, I am requiring the user''s default group. I also want to require supplemental groups if provided by the parameter $groups. Also, is the way I do groups => $groups going to fail if it''s empty or if it''s just a string (i.e., defines just one group instead of an array)? Links to the appropriate documentation would be greatly appreciated of course! -- 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.
jcbollinger
2011-Nov-30 14:25 UTC
[Puppet Users] Re: How do I require a resource in a definition based on an array parameter?
On Nov 29, 3:01 pm, beamin melbin <belm...@gmail.com> wrote:> I have a define that looks like this: > > define user::sys_user($fullname, $uid, $groups, $shell=''/bin/bash'', > $authkey, $authkey_type=rsa) { > $username = "sys_${name}" > group { $username: > gid => $uid, > } > > user { $username: > require => Group[$username], > ensure => present, > uid => $uid, > gid => $uid, > groups => $groups, > comment => $fullname, > shell => $shell, > managehome => true, > allowdupe => false, > }It would be slightly better to do this: user { $username: uid => ${uid}, gid => ${username}, # no ''require'' needed for the primary group # ... } Puppet will auto-require the user''s primary group if that group is under management, but I think Puppet needs you to identify the group by name instead of ID for it to be able to recognize that it can do so.> ssh_authorized_key { "${username}_authkey": > user => $username, > ensure => present, > key => $authkey, > type => $authkey_type, > } > > } > > In the user resource, I am requiring the user''s default group.Which is unnecessary, as described above.> I also > want to require supplemental groups if provided by the parameter > $groups.It turns out that obtaining an array of resource references from an array of resource names is a fairly hard problem. You might be best off refactoring the relationships to a higher level. For example, you are apparently managing the supplemental groups elsewhere, so put all the Group resources that *could* appear as supplemental groups into a class, and have your definition require that class. (I would do that with the ''require'' function in the definition''s body instead of with the ''require'' metaparameter to every instance declaration).> Also, is the way I do groups => $groups going to fail if it''s empty or > if it''s just a string (i.e., defines just one group instead of an > array)?It should be fine as a single group name. I''m not sure off-hand about an empty string.> Links to the appropriate documentation would be greatly appreciated of > course!Well, PuppetLabs''s documentation index is at http://docs.puppetlabs.com/, if you didn''t already know that. The "Learning Puppet" section contains several documents that might have a bit of relevance, and elsewhere on that page you will find links to the resource type reference and language guide. I''m not sure that any of those will really speak very well to the questions you have asked, however. 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.