diff options
author | Toshio Kuratomi <toshio@fedoraproject.org> | 2014-12-12 12:08:03 -0800 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2015-02-17 14:37:59 -0600 |
commit | c75c8c2a99a8ef97039d84c73ce96c85b152fa08 (patch) | |
tree | b5373e0bdda0e42497ec794376a6f2830b394fc4 | |
parent | cb7dce8a150d55131a4a7d8dbccb344659dbd8a0 (diff) | |
download | ansible-modules-core-c75c8c2a99a8ef97039d84c73ce96c85b152fa08.tar.gz |
Don't traceback if a gid is specified instead of a group name
Fixes https://github.com/ansible/ansible/issues/9796
-rw-r--r-- | system/user.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/system/user.py b/system/user.py index 6fe20122..44dffba3 100644 --- a/system/user.py +++ b/system/user.py @@ -447,21 +447,23 @@ class User(object): def group_exists(self,group): try: - if group.isdigit(): - if grp.getgrgid(int(group)): - return True - else: - if grp.getgrnam(group): - return True - except KeyError: - return False + # Try group as a gid first + grp.getgrgid(int(group)) + return True + except (ValueError, KeyError): + try: + grp.getgrnam(group) + return True + except KeyError: + return False - def group_info(self,group): + 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): |