Fixes issue #315

This adds some logic when usings groups possibly in combination with append

  if just specifying groups and the current groups do not match the list
     set groups
  if specifying groups with append and any group thats not in the current groups
     set groups with -a
This commit is contained in:
Brendan Beveridge 2012-05-08 09:43:51 +10:00
parent d6e56dee87
commit 96c0ee0efc

View file

@ -135,14 +135,28 @@ def user_mod(user, **kwargs):
cmd.append('-g') cmd.append('-g')
cmd.append(kwargs[key]) cmd.append(kwargs[key])
elif key == 'groups' and kwargs[key] is not None: elif key == 'groups' and kwargs[key] is not None:
defined_groups = kwargs[key].split(',') current_groups = user_group_membership(user)
for g in defined_groups: groups = kwargs[key].split(',')
for g in groups:
if not group_exists(g): if not group_exists(g):
fail_json(msg="Group %s does not exist" % (g)) fail_json(msg="Group %s does not exist" % (g))
existing_groups = user_group_membership(user) group_diff = set(sorted(current_groups)).symmetric_difference(set(sorted(groups)))
if sorted(defined_groups) != sorted(existing_groups): groups_need_mod = False
if group_diff:
if kwargs['append'] is not None and kwargs['append'] == 'yes':
for g in groups:
if g in group_diff:
cmd.append('-a')
groups_need_mod = True
else:
debug("groups differ, trigger usemod")
groups_need_mod = True
if groups_need_mod:
cmd.append('-G') cmd.append('-G')
cmd.append(kwargs[key]) cmd.append(','.join(groups))
elif key == 'comment': elif key == 'comment':
if kwargs[key] is not None and info[4] != kwargs[key]: if kwargs[key] is not None and info[4] != kwargs[key]:
cmd.append('-c') cmd.append('-c')