From c4838286aceaeb8cadef4c93cc8ff0b36e401126 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 15 Jun 2016 07:02:56 -0700 Subject: [PATCH] Make sure we don't end up with an empty PYTHONPATH (#16240) When the PYTHONPATH is an empty string python will treat it as though the cwd is in the PYTHONPATH. This can be undesirable. So make sure we delete PYTHONPATH from the environment altgether in this case. Fixes #16195 --- lib/ansible/module_utils/basic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 0122c736e8..e3c0e32a51 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -2038,6 +2038,8 @@ class AnsibleModule(object): if not x.endswith('/ansible_modlib.zip') \ and not x.endswith('/debug_dir')] os.environ['PYTHONPATH'] = ':'.join(pypaths) + if not os.environ['PYTHONPATH']: + del os.environ['PYTHONPATH'] # create a printable version of the command for use # in reporting later, which strips out things like