From 74833f730bb277b09176896515c8a52846d1f566 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Fri, 11 Oct 2013 09:10:35 -0400 Subject: [PATCH] Fixes #4312 for older versions of usermod which do not have --append --- system/user | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/system/user b/system/user index 9dbc3305861..4375bcb011f 100644 --- a/system/user +++ b/system/user @@ -313,9 +313,28 @@ class User(object): return self.execute_command(cmd) + def _check_usermod_append(self): + # check if this version of usermod can append groups + + cmd = [self.module.get_bin_path('usermod', True)] + cmd.append('--help') + rc, data1, data2 = self.execute_command(cmd) + helpout = data1 + data2 + + # check if --append exists + lines = helpout.split('\n') + for line in lines: + if line.strip().startswith('-a, --append'): + return True + + return False + + + def modify_user_usermod(self): cmd = [self.module.get_bin_path('usermod', True)] info = self.user_info() + has_append = self._check_usermod_append() if self.uid is not None and info[2] != int(self.uid): cmd.append('-u') @@ -348,15 +367,21 @@ class User(object): if self.append: for g in groups: if g in group_diff: - cmd.append('-a') + if has_append: + cmd.append('-a') groups_need_mod = True break else: groups_need_mod = True if groups_need_mod: - cmd.append('-G') - cmd.append(','.join(groups)) + if self.append and not has_append: + cmd.append('-A') + cmd.append(','.join(group_diff)) + else: + cmd.append('-G') + cmd.append(','.join(groups)) + if self.comment is not None and info[4] != self.comment: cmd.append('-c')