Matthias Pigulla
2011-Sep-27 21:17 UTC
[Puppet Users] create_resources (or variable scoping?) question
Hi all, I would like to create a configuration along the lines of complex_user { "joe": uid => 42, sshkeys => { "key1-comment" => { key => "...", ... }, "key2-comment" => { key => "...", ...} } ... } That is, a definition that will create a user and several ssh_authorized_keys belonging to him/her, among other things. The idea is that such a definition makes it easier to keep users and keys together, not having to repeat the user name in the key definition, being able to enable/disable both together etc. My problem is that I cannot figure out how to get the ssh_authorized_keys to work from the definition of complex_user - more precisely, how to pass the "user" into it. Here''s what I tried: define complex_user($uid, $sshkeys) { /* ... create user with $name ... */ create_resources("keys_for", $sshkeys) } define keys_for($key) { ... } In keys_for, $key is the "key" value from the hash and $name is the comment from above, but I can no longer access complex_user''s $name. Any ideas how to get this working (or why not to do it at all)? Thanks! -mp. -- 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.
Matthias Pigulla
2011-Sep-27 21:45 UTC
[Puppet Users] AW: create_resources (or variable scoping?) question
Replying to myself:> define complex_user($uid, $sshkeys) { > /* ... create user with $name ... */ > create_resources("keys_for", $sshkeys) > } > > define keys_for($key) { ... }I just found that when having a $user_name = $name in complex_user, I can access that in keys_for simply as $user_name and it seems to work (TM). Is that a legitimate approach or discouraged? I''ve read http://docs.puppetlabs.com/guides/scope_and_puppet.html but that does not say anything about definitions? -mp. -- 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-Sep-28 13:39 UTC
[Puppet Users] Re: create_resources (or variable scoping?) question
On Sep 27, 4:45 pm, Matthias Pigulla <m...@webfactory.de> wrote:> Replying to myself: > > > define complex_user($uid, $sshkeys) { > > /* ... create user with $name ... */ > > create_resources("keys_for", $sshkeys) > > } > > > define keys_for($key) { ... } > > I just found that when having a $user_name = $name in complex_user, I can access that in keys_for simply as $user_name and it seems to work (TM). > > Is that a legitimate approach or discouraged? I''ve readhttp://docs.puppetlabs.com/guides/scope_and_puppet.htmlbut that does not say anything about definitions?If your keys_for definition were nested inside your complex_user definition then I think that would resolve the variable scoping issue. If it works at all, that is, which I''m not sure it would. Otherwise, your approach relies on dynamic scoping, which should evoke a warning in 2.7.x and will fail in 2.8.x. 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.