On Monday, November 18, 2013 10:41:39 PM UTC-6, Rich Burroughs wrote:
>
> If you really mean assign, no. UIDs are managed through the user resource 
> type:
>
> http://docs.puppetlabs.com/references/latest/type.html#user
>
>
>

Well, that's what Stuart is using.  He switched up on you.

I take the question to be "is there a way to declare different UIDs for 
different users in an array-titled User declaration?".  The basic answer is 
"not as such".  The whole point of the array-title resource declaration 
shortcut is that all the resources declared via any one such declaration 
get the same parameter declarations.

That does not mean you cannot both use compact forms and assign different 
parameters per user, however.  There are several alternatives.  One of the 
simpler ones is to use resource parameter defaults (beware: unlike 
variables, parameter defaults have dynamic scope) and multiple-distinct 
resources per resource declaration block.  Example:

class mymodule::users {
  # These default parameters apply to all Users declared
  # in this dynamic scope:
  User {
    ensure     => 'present',
    gid        => 'users',
    managehome => true,
    shell      => '/bin/bash'
  }

  # such as these:
  user {
    'alice':   uid => 501;
    'bob':     uid => 502;
    'charlie': uid => 503;
  }
}

Another alternative is to use a defined-type wrapper to adapt your data 
source to the User resource type:

class mymodule {
  # A data source:
  $user_uids = {
    'david' => 504,
    'emily' => 505,
    'frank' => 506
  }
}

# An adapter definition:
define mymodule::local_user(
    $ensure = 'present',
    $gid = 'users',
    $managehome = 'true',
    $shell = '/bin/bash') {
  include 'mymodule'
  user { $title:
    ensure => $ensure,
    # Here's where the magic happens:
    uid => $mymodule::user_uids[$title],
    gid => $gid,
    managehome => $managehome,
    shell => $shell
  }
}

# The resource-declaring class:
class mymodule::other_users {
  include 'mymodule'
  # The keys() function is from the puppetlabs-stdlib module
  $declared_users = keys($mymodule::user_uids)
  mymodule::local_user { $declared_users: }
}

That's not an improvement for so few users, but by the time you get up even 
to tens of users it's a win.  Moreover, it's all driven by the single data 
source, so you there is no risk of different data sources falling out of 
sync with each other.

If the point is to keep your manifests simple, but you don't mind the data 
being complex and repetitive, then you also have the option of declaring 
multiple resources of the same type with whatever parameters you want via 
the built-in create_resources() function.  That might make sense if the 
data are being loaded from an external source, perhaps via Hiera 
(recommended):

class my_module::still_more_users {
  $user_data = hiera('still_more_users')
  create_resources('user', $user_data)
}

You can't get much simpler than that on the manifest side, but you need to 
express all the non-default parameter values in the data.


John 

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/06b0c9bf-c8a4-4005-b6e8-58f69721a4e0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to