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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.