Don't traceback if a gid is specified instead of a group name
Fixes https://github.com/ansible/ansible/issues/9796
This commit is contained in:
parent
f4625a3dd1
commit
e1f90635af
1 changed files with 14 additions and 12 deletions
|
@ -447,11 +447,12 @@ class User(object):
|
|||
|
||||
def group_exists(self,group):
|
||||
try:
|
||||
if group.isdigit():
|
||||
if grp.getgrgid(int(group)):
|
||||
# Try group as a gid first
|
||||
grp.getgrgid(int(group))
|
||||
return True
|
||||
else:
|
||||
if grp.getgrnam(group):
|
||||
except (ValueError, KeyError):
|
||||
try:
|
||||
grp.getgrnam(group)
|
||||
return True
|
||||
except KeyError:
|
||||
return False
|
||||
|
@ -459,9 +460,10 @@ class User(object):
|
|||
def group_info(self, group):
|
||||
if not self.group_exists(group):
|
||||
return False
|
||||
if group.isdigit():
|
||||
return list(grp.getgrgid(group))
|
||||
else:
|
||||
try:
|
||||
# Try group as a gid first
|
||||
return list(grp.getgrgid(int(group)))
|
||||
except (ValueError, KeyError):
|
||||
return list(grp.getgrnam(group))
|
||||
|
||||
def get_groups_set(self, remove_existing=True):
|
||||
|
|
Loading…
Reference in a new issue