diff options
author | Artem Goncharov <Artem.goncharov@gmail.com> | 2018-05-17 23:22:40 +0200 |
---|---|---|
committer | Sam Doran <sdoran@redhat.com> | 2018-05-17 17:22:40 -0400 |
commit | db786b846f347b2dbadf1794346e6949767788b9 (patch) | |
tree | 04558365af056ef90061b88749841a7dde7f022b | |
parent | 82f6f0871231ed971bfad86d0975f8333c6d765a (diff) | |
download | ansible-db786b846f347b2dbadf1794346e6949767788b9.tar.gz |
fixes issue 39472: (#40341)
With python 3.6 spwd.getspnam returns PermissionError instead of
KeyError if user does not have privileges
-rw-r--r-- | changelogs/fragments/py36-spwd.yaml | 3 | ||||
-rw-r--r-- | lib/ansible/modules/system/user.py | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/changelogs/fragments/py36-spwd.yaml b/changelogs/fragments/py36-spwd.yaml new file mode 100644 index 0000000000..7b867baa8e --- /dev/null +++ b/changelogs/fragments/py36-spwd.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- spwd - With python 3.6 spwd.getspnam returns PermissionError instead of KeyError if user does not have privileges (https://github.com/ansible/ansible/issues/39472) diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py index 7d15687c79..472904c081 100644 --- a/lib/ansible/modules/system/user.py +++ b/lib/ansible/modules/system/user.py @@ -236,6 +236,7 @@ EXAMPLES = ''' ''' +import errno import grp import os import platform @@ -646,6 +647,13 @@ class User(object): return passwd, expires except KeyError: return passwd, expires + except OSError as e: + # Python 3.6 raises PermissionError instead of KeyError + # Due to absence of PermissionError in python2.7 need to check + # errno + if e.errno in (errno.EACCES, errno.EPERM): + return passwd, expires + raise if not self.user_exists(): return passwd, expires |