[stable-2.20] Fix getuser fallback error handling (#86144) (#86167)

(cherry picked from commit 4184d96)

Co-authored-by: Matt Clay <matt@mystile.com>
This commit is contained in:
Abhijeet Kasurde
2025-11-24 09:17:12 -06:00
committed by GitHub
co-authored by Matt Clay
parent 79a243940f
commit 4e2136cdbd
3 changed files with 8 additions and 2 deletions
@@ -0,0 +1,4 @@
bugfixes:
- display - Fix ``getuser`` fallback error handling on Python 3.13 and later.
(https://github.com/ansible/ansible/issues/86142)
- local connection - Fix ``getuser`` fallback error handling on Python 3.13 and later.
+2 -1
View File
@@ -67,7 +67,8 @@ class Connection(ConnectionBase):
self.cwd = None
try:
self.default_user = getpass.getuser()
except KeyError:
except (ImportError, KeyError, OSError):
# deprecated: description='only OSError is required for Python 3.13+' python_version='3.12'
display.vv("Current user (uid=%s) does not seem to exist on this system, leaving user empty." % os.getuid())
self.default_user = ""
+2 -1
View File
@@ -174,7 +174,8 @@ class FilterUserInjector(logging.Filter):
try:
username = getpass.getuser()
except KeyError:
except (ImportError, KeyError, OSError):
# deprecated: description='only OSError is required for Python 3.13+' python_version='3.12'
# people like to make containers w/o actual valid passwd/shadow and use host uids
username = 'uid=%s' % os.getuid()