fixes issue 39472: (#40379)

With python 3.6 spwd.getspnam returns PermissionError instead of
KeyError if user does not have privileges

(cherry picked from commit 0023b1ee9e)
pull/40548/head
Artem Goncharov 8 years ago committed by Sam Doran
parent 7c49648a39
commit 13c88fe2d2

@ -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)

@ -218,6 +218,7 @@ EXAMPLES = '''
expires: 1422403387
'''
import errno
import grp
import os
import platform
@ -616,6 +617,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

Loading…
Cancel
Save