mirror of
https://github.com/ansible/ansible.git
synced 2025-11-30 23:16:08 +07:00
Fix getuser fallback error handling (#86144)
This commit is contained in:
4
changelogs/fragments/getuser-exception-handling.yml
Normal file
4
changelogs/fragments/getuser-exception-handling.yml
Normal 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.
|
||||
@@ -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 = ""
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user