2008-10-20 22:17:48 +02:00
|
|
|
#
|
|
|
|
# user module
|
|
|
|
#
|
2007-12-27 12:08:19 +01:00
|
|
|
# Copyright (C) 2007 admin@immerda.ch
|
2008-10-20 22:17:48 +02:00
|
|
|
# Copyright 2008, Puzzle ITC
|
|
|
|
# Marcel Härry haerry+puppet(at)puzzle.ch
|
|
|
|
# Simon Josi josi+puppet(at)puzzle.ch
|
2007-12-27 12:08:19 +01:00
|
|
|
#
|
2008-10-20 22:17:48 +02:00
|
|
|
# This program is free software; you can redistribute
|
|
|
|
# it and/or modify it under the terms of the GNU
|
|
|
|
# General Public License version 3 as published by
|
|
|
|
# the Free Software Foundation.
|
2007-12-27 12:08:19 +01:00
|
|
|
|
2008-10-01 22:16:08 +02:00
|
|
|
# ssh:_key have to be handed over as the classname
|
|
|
|
# containing the ssh_keys
|
2007-12-27 12:08:19 +01:00
|
|
|
define user::define_user(
|
2008-10-20 22:17:48 +02:00
|
|
|
$name_comment = 'absent',
|
|
|
|
$uid = 'absent',
|
|
|
|
$gid = 'absent',
|
2008-10-20 09:15:22 +02:00
|
|
|
$groups = [],
|
2008-10-19 18:14:01 +02:00
|
|
|
$membership = 'minimum',
|
2008-10-20 22:17:48 +02:00
|
|
|
$homedir = 'absent',
|
|
|
|
$managehome = 'true',
|
|
|
|
$homedir_mode = '0750',
|
|
|
|
$sshkey = 'absent',
|
|
|
|
$shell = 'absent'
|
2008-10-06 22:33:54 +02:00
|
|
|
){
|
2008-10-20 22:17:48 +02:00
|
|
|
|
|
|
|
$real_homedir = $homedir ? {
|
|
|
|
'absent' => "/home/$name",
|
|
|
|
default => $homedir
|
2008-10-06 22:33:54 +02:00
|
|
|
}
|
2007-12-27 12:08:19 +01:00
|
|
|
|
2008-10-06 22:33:54 +02:00
|
|
|
$real_name_comment = $name_comment ? {
|
2008-10-20 22:17:48 +02:00
|
|
|
'absent' => $name,
|
|
|
|
default => $name_comment,
|
2008-10-06 22:33:54 +02:00
|
|
|
}
|
2008-01-03 18:19:00 +01:00
|
|
|
|
2008-10-06 22:33:54 +02:00
|
|
|
$real_shell = $shell ? {
|
2008-10-20 22:17:48 +02:00
|
|
|
'absent' => $operatingsystem ? {
|
|
|
|
openbsd => "/usr/local/bin/bash",
|
|
|
|
default => "/bin/bash",
|
|
|
|
},
|
2008-10-06 22:33:54 +02:00
|
|
|
default => $shell,
|
|
|
|
}
|
2007-12-27 12:08:19 +01:00
|
|
|
|
2008-10-06 22:33:54 +02:00
|
|
|
user { $name:
|
|
|
|
allowdupe => false,
|
|
|
|
comment => "$real_name_comment",
|
|
|
|
ensure => present,
|
2008-10-20 22:17:48 +02:00
|
|
|
home => $real_homedir,
|
|
|
|
managehome => $managehome,
|
2008-10-06 22:33:54 +02:00
|
|
|
shell => $real_shell,
|
2008-10-19 18:14:01 +02:00
|
|
|
groups => $groups,
|
|
|
|
membership => $membership,
|
2008-10-06 22:33:54 +02:00
|
|
|
}
|
2007-12-27 12:08:19 +01:00
|
|
|
|
2008-10-20 22:17:48 +02:00
|
|
|
file{"$real_homedir":
|
|
|
|
ensure => directory,
|
|
|
|
require => User[$name],
|
2008-10-20 22:30:18 +02:00
|
|
|
owner => $name, mode => $homedir_mode;
|
2008-10-20 22:17:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case $uid {
|
|
|
|
'absent': { info("Not defining a uid for user $name") }
|
|
|
|
default: {
|
|
|
|
User[$name]{
|
|
|
|
uid => $uid,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case $gid {
|
|
|
|
'absent': { info("Not defining a gid for user $name") }
|
|
|
|
default: {
|
|
|
|
User[$name]{
|
|
|
|
gid => $gid,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case $name {
|
|
|
|
root: {}
|
|
|
|
default: {
|
|
|
|
group { $name:
|
|
|
|
allowdupe => false,
|
|
|
|
ensure => present,
|
|
|
|
require => User[$name],
|
|
|
|
}
|
|
|
|
case $gid {
|
|
|
|
'absent': { info("not defining a gid for group $name") }
|
|
|
|
default: {
|
|
|
|
Group[$name]{
|
|
|
|
gid => $gid,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case $gid {
|
2008-10-20 22:30:18 +02:00
|
|
|
'absent': {
|
|
|
|
File[$real_homedir]{
|
|
|
|
group => $name,
|
|
|
|
}
|
|
|
|
}
|
2008-10-20 22:17:48 +02:00
|
|
|
default: {
|
|
|
|
File[$real_homedir]{
|
|
|
|
group => $gid,
|
2008-10-06 22:33:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-27 12:08:19 +01:00
|
|
|
|
2008-10-20 22:23:12 +02:00
|
|
|
case $sshkey {
|
|
|
|
'absent': { info("no sshkey to manage for user $name") }
|
2008-01-03 18:31:17 +01:00
|
|
|
default: {
|
2008-10-06 22:39:01 +02:00
|
|
|
User[$name]{
|
2008-10-20 22:23:12 +02:00
|
|
|
before => Class[$sshkey],
|
2008-10-06 22:39:01 +02:00
|
|
|
}
|
2008-10-20 22:23:12 +02:00
|
|
|
include $sshkey
|
2008-01-03 18:32:10 +01:00
|
|
|
}
|
2008-01-03 18:30:00 +01:00
|
|
|
}
|
2007-12-27 12:08:19 +01:00
|
|
|
}
|