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,21 +447,23 @@ class User(object):
|
||||||
|
|
||||||
def group_exists(self,group):
|
def group_exists(self,group):
|
||||||
try:
|
try:
|
||||||
if group.isdigit():
|
# Try group as a gid first
|
||||||
if grp.getgrgid(int(group)):
|
grp.getgrgid(int(group))
|
||||||
return True
|
return True
|
||||||
else:
|
except (ValueError, KeyError):
|
||||||
if grp.getgrnam(group):
|
try:
|
||||||
return True
|
grp.getgrnam(group)
|
||||||
except KeyError:
|
return True
|
||||||
return False
|
except KeyError:
|
||||||
|
return False
|
||||||
|
|
||||||
def group_info(self,group):
|
def group_info(self, group):
|
||||||
if not self.group_exists(group):
|
if not self.group_exists(group):
|
||||||
return False
|
return False
|
||||||
if group.isdigit():
|
try:
|
||||||
return list(grp.getgrgid(group))
|
# Try group as a gid first
|
||||||
else:
|
return list(grp.getgrgid(int(group)))
|
||||||
|
except (ValueError, KeyError):
|
||||||
return list(grp.getgrnam(group))
|
return list(grp.getgrnam(group))
|
||||||
|
|
||||||
def get_groups_set(self, remove_existing=True):
|
def get_groups_set(self, remove_existing=True):
|
||||||
|
|
Loading…
Reference in a new issue