add a define to manage users in groups
This commit is contained in:
parent
8671c39470
commit
33b7ff7bea
1 changed files with 27 additions and 0 deletions
27
manifests/groups/manage_user.pp
Normal file
27
manifests/groups/manage_user.pp
Normal 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}']",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue