avoid key errors on environment access (#72620)

pull/72653/head
Brian Coca 4 years ago committed by GitHub
parent ad4ddd8211
commit 07248e5ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- avoid possible errors accessing os.environ by not assuming existance of variables.

@ -1020,7 +1020,7 @@ def start_connection(play_context, variables, task_uuid):
Starts the persistent connection
'''
candidate_paths = [C.ANSIBLE_CONNECTION_PATH or os.path.dirname(sys.argv[0])]
candidate_paths.extend(os.environ['PATH'].split(os.pathsep))
candidate_paths.extend(os.environ.get('PATH', '').split(os.pathsep))
for dirname in candidate_paths:
ansible_connection = os.path.join(dirname, 'ansible-connection')
if os.path.isfile(ansible_connection):

@ -2649,8 +2649,12 @@ class AnsibleModule(object):
old_env_vals[key] = os.environ.get(key, None)
os.environ[key] = val
if path_prefix:
old_env_vals['PATH'] = os.environ['PATH']
os.environ['PATH'] = "%s:%s" % (path_prefix, os.environ['PATH'])
path = os.environ.get('PATH', '')
old_env_vals['PATH'] = path
if path:
os.environ['PATH'] = "%s:%s" % (path_prefix, path)
else:
os.environ['PATH'] = path_prefix
# If using test-module.py and explode, the remote lib path will resemble:
# /tmp/test_module_scratch/debug_dir/ansible/module_utils/basic.py

Loading…
Cancel
Save