respawn: Update ENV dict copy with PYTHONPATH value (#84962)

* Use shallow copy of os.environ to update PYTHONPATH value
  instead of using '|' operator

Fixes: #84954

Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde
2025-04-10 15:14:24 -04:00
committed by GitHub
parent 4bc4030988
commit 82e4b469f6
2 changed files with 8 additions and 2 deletions
+3
View File
@@ -0,0 +1,3 @@
---
bugfixes:
- respawn - use copy of env variables to update existing PYTHONPATH value (https://github.com/ansible/ansible/issues/84954).
+5 -2
View File
@@ -56,10 +56,13 @@ def probe_interpreters_for_module(interpreter_paths, module_name):
:arg interpreter_paths: iterable of paths to Python interpreters. The paths will be probed :arg interpreter_paths: iterable of paths to Python interpreters. The paths will be probed
in order, and the first path that exists and can successfully import the named module will in order, and the first path that exists and can successfully import the named module will
be returned (or ``None`` if probing fails for all supplied paths). be returned (or ``None`` if probing fails for all supplied paths).
:arg module_name: fully-qualified Python module name to probe for (eg, ``selinux``) :arg module_name: fully-qualified Python module name to probe for (for example, ``selinux``)
""" """
PYTHONPATH = os.getenv('PYTHONPATH', '') PYTHONPATH = os.getenv('PYTHONPATH', '')
env = os.environ | {'PYTHONPATH': f'{_ANSIBLE_PARENT_PATH}:{PYTHONPATH}'.rstrip(': ')} env = os.environ.copy()
env.update({
'PYTHONPATH': f'{_ANSIBLE_PARENT_PATH}:{PYTHONPATH}'.rstrip(': ')
})
for interpreter_path in interpreter_paths: for interpreter_path in interpreter_paths:
if not os.path.exists(interpreter_path): if not os.path.exists(interpreter_path):
continue continue