module-user/manifests/groups/manage_user.pp

28 lines
621 B
ObjectPascal
Raw Permalink Normal View History

2010-05-20 02:14:25 +02:00
define user::groups::manage_user(
2012-06-05 22:45:46 +02:00
$ensure = 'present',
$group,
$user = 'absent'
2010-05-20 02:14:25 +02:00
){
2012-06-05 22:45:46 +02:00
if ($user != 'absent'){
$real_user = $user
} else {
$real_user = $name
}
2010-05-20 02:14:25 +02:00
2012-06-05 22:45:46 +02:00
augeas{"manage_${real_user}_in_group_${group}":
context => '/files/etc/group',
}
if ($ensure == 'present'){
Augeas["manage_${real_user}_in_group_${group}"]{
changes => [ "set ${group}/user[last()+1] ${real_user}" ],
onlyif => "match ${group}/*[../user='${real_user}'] size == 0"
2010-05-20 02:14:25 +02:00
}
2012-06-05 22:45:46 +02:00
} else {
Augeas["manage_${real_user}_in_group_${group}"]{
changes => "rm ${group}/user[.='${real_user}']",
2010-05-20 02:14:25 +02:00
}
2012-06-05 22:45:46 +02:00
}
2010-05-20 02:14:25 +02:00
}