add a define to manage users in groups

This commit is contained in:
mh 2010-05-20 02:14:25 +02:00
parent 8671c39470
commit 33b7ff7bea

View file

@ -0,0 +1,27 @@
define user::groups::manage_user(
$ensure = 'present',
$group,
$user = 'absent'
){
if ($user != 'absent'){
$real_user = $user
} else {
$real_user = $name
}
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"
}
} else {
Augeas["manage_${real_user}_in_group_${group}"]{
changes => "rm ${group}/user[.='${real_user}']",
}
}
}