AnOnJoe
2012-Nov-26 11:00 UTC
[Puppet Users] What is the best way for creating users in puppet/hiera ?
Hello, I have recently discover hiera, and I would like to use it for creating users on my node. I first think of someting like that : common.yaml> lusers : - jodoe > - jadoe >classes : - users>serv01.foo.com.yaml> lusers : - Alice > - Bob >modules/users/manifest/init.pp> define users ($user = hiera("$lusers")) { > user { "$user": > ensure => present, > shell => ''/bin/bash'', > home => "/home/$user", > managehome => true, > } > } >But I don''t know how I can call my def type like that. What about you ? How do you create your users in puppet / hiera ? Thx -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/yywCgTGmJAwJ. 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.
Ellison Marks
2012-Nov-26 17:51 UTC
[Puppet Users] Re: What is the best way for creating users in puppet/hiera ?
You might look into the create_resources function. The example given is creating users even. http://docs.puppetlabs.com/references/latest/function.html#createresources On Monday, November 26, 2012 3:00:17 AM UTC-8, AnOnJoe wrote:> > Hello, > I have recently discover hiera, and I would like to use it for creating > users on my node. > > I first think of someting like that : > > > common.yaml > >> lusers : - jodoe >> - jadoe >> > classes : - users >> > > > serv01.foo.com.yaml > >> lusers : - Alice >> - Bob >> > > > modules/users/manifest/init.pp > >> define users ($user = hiera("$lusers")) { >> user { "$user": >> ensure => present, >> shell => ''/bin/bash'', >> home => "/home/$user", >> managehome => true, >> } >> } >> > > But I don''t know how I can call my def type like that. > > What about you ? How do you create your users in puppet / hiera ? > > Thx > > > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/i4IfAKLco48J. 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
2012-Nov-26 19:20 UTC
[Puppet Users] Re: What is the best way for creating users in puppet/hiera ?
On Monday, November 26, 2012 5:00:17 AM UTC-6, AnOnJoe wrote:> > Hello, > I have recently discover hiera, and I would like to use it for creating > users on my node. > > I first think of someting like that : > > > common.yaml > >> lusers : - jodoe >> - jadoe >> > classes : - users >> > > > serv01.foo.com.yaml > >> lusers : - Alice >> - Bob >> > > > modules/users/manifest/init.pp > >> define users ($user = hiera("$lusers")) { >> user { "$user": >> ensure => present, >> shell => ''/bin/bash'', >> home => "/home/$user", >> managehome => true, >> } >> } >> > > But I don''t know how I can call my def type like that. > > What about you ? How do you create your users in puppet / hiera ? > >A module''s init.pp, if non-empty, should contain only the definition of a class (not a definition) sharing the name of the module. That''s what you want in this case anyway: modules/users/manifests/init.pp: class users { $users = flatten(hiera_array(''lusers'')) user::user { $users: } } modules/users/manifests/user.pp define user::user () { user { "$name": ensure => present, shell => ''/bin/bash'', home => "/home/$name", managehome => true } } Notes: 1. To collect values for the same key from multiple levels of your data hierarchy, you need to use either hiera_array() or hiera_hash(). The plain hiera() function will give you only the value from the highest-priority level. 2. The flatten() function comes from the "stdlib" add-on module. You would need it in the example because, with the data as given, hiera_array() will return an array of arrays, whereas you want a single array whose elements are the usernames. 3. The only reason you need a defined type is that you want to explicitly declare the home directory name based on the username. If none of the properties were derived from the username then you could just use native User resources directly. 4. All quoting (and non-quoting) in the example is exactly as you should have it. In several cases, adding quotes or changing the quote type will change the meaning. 5. You would use the example by via "include ''users''" John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/E2I5jMIfGMMJ. 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.
AnOnJoe
2012-Nov-28 14:33 UTC
[Puppet Users] Re: What is the best way for creating users in puppet/hiera ?
thx Elison, my users are now created via the create_resources function, and it works like a charm. and thx jcbollinge, you show me the right way in using puppet/hiera. I have now a lot of work to normalize my modules ;-) Le lundi 26 novembre 2012 20:20:12 UTC+1, jcbollinger a écrit :> > > > On Monday, November 26, 2012 5:00:17 AM UTC-6, AnOnJoe wrote: >> >> Hello, >> I have recently discover hiera, and I would like to use it for creating >> users on my node. >> >> I first think of someting like that : >> >> >> common.yaml >> >>> lusers : - jodoe >>> - jadoe >>> >> classes : - users >>> >> >> >> serv01.foo.com.yaml >> >>> lusers : - Alice >>> - Bob >>> >> >> >> modules/users/manifest/init.pp >> >>> define users ($user = hiera("$lusers")) { >>> user { "$user": >>> ensure => present, >>> shell => ''/bin/bash'', >>> home => "/home/$user", >>> managehome => true, >>> } >>> } >>> >> >> But I don''t know how I can call my def type like that. >> >> What about you ? How do you create your users in puppet / hiera ? >> >> > > A module''s init.pp, if non-empty, should contain only the definition of a > class (not a definition) sharing the name of the module. That''s what you > want in this case anyway: > > modules/users/manifests/init.pp: > > class users { > $users = flatten(hiera_array(''lusers'')) > user::user { $users: } > } > > > modules/users/manifests/user.pp > > define user::user () { > user { "$name": > ensure => present, > shell => ''/bin/bash'', > home => "/home/$name", > managehome => true > } > } > > > Notes: > > 1. To collect values for the same key from multiple levels of your > data hierarchy, you need to use either hiera_array() or hiera_hash(). The > plain hiera() function will give you only the value from the > highest-priority level. > 2. The flatten() function comes from the "stdlib" add-on module. You would > need it in the example because, with the data as given, hiera_array() will > return an array of arrays, whereas you want a single array whose elements > are the usernames. > 3. The only reason you need a defined type is that you want to > explicitly declare the home directory name based on the username. If none > of the properties were derived from the username then you could just use > native User resources directly. > 4. All quoting (and non-quoting) in the example is exactly as you > should have it. In several cases, adding quotes or changing the quote type > will change the meaning. > 5. You would use the example by via "include ''users''" > > > John > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/g33IHWw3G44J. 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.