Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport/2.13/78040 #78054

Merged
merged 1 commit into from Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/permission-denied-spwd-module.yml
@@ -0,0 +1,2 @@
bugfixes:
- user - Fix error "Permission denied" in user module while generating SSH keys (https://github.com/ansible/ansible/issues/78017).
12 changes: 11 additions & 1 deletion lib/ansible/modules/user.py
Expand Up @@ -1052,7 +1052,17 @@ def set_password_expire(self):
max_needs_change = self.password_expire_max is not None

if HAVE_SPWD:
shadow_info = spwd.getspnam(self.name)
try:
shadow_info = spwd.getspnam(self.name)
except KeyError:
return None, '', ''
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, errno.ENOENT):
return None, '', ''
raise
min_needs_change &= self.password_expire_min != shadow_info.sp_min
max_needs_change &= self.password_expire_max != shadow_info.sp_max

Expand Down