Fix getuser fallback error handling (#86144)

This commit is contained in:
Matt Clay
2025-11-06 17:57:23 -08:00
committed by GitHub
parent 707a5ec617
commit 4184d9665e
3 changed files with 8 additions and 2 deletions

View File

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

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 = ""

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