From 8e5f502d001769680eb23e34c550e6cc04fa4fb3 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Tue, 14 Jun 2016 15:20:41 -0400 Subject: [PATCH] Use ansible venv to be used during inv import --- awx/main/management/commands/inventory_import.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py index e32c924538..60d86a9cfd 100644 --- a/awx/main/management/commands/inventory_import.py +++ b/awx/main/management/commands/inventory_import.py @@ -362,7 +362,19 @@ class ExecutableJsonLoader(BaseLoader): raise RuntimeError("proot is not installed but is configured for use") kwargs = {'proot_temp_dir': self.source_dir} # TODO: Remove proot dir cmd = wrap_args_with_proot(cmd, self.source_dir, **kwargs) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # Use ansible venv if it's available and setup to use + env = dict(os.environ.items()) + if settings.ANSIBLE_USE_VENV: + env['VIRTUAL_ENV'] = settings.ANSIBLE_VENV_PATH + env['PATH'] = os.path.join(settings.ANSIBLE_VENV_PATH, "bin") + ":" + env['PATH'] + venv_libdir = os.path.join(settings.ANSIBLE_VENV_PATH, "lib") + env.pop('PYTHONPATH', None) # default to none if no python_ver matches + for python_ver in ["python2.7", "python2.6"]: + if os.path.isdir(os.path.join(venv_libdir, python_ver)): + env['PYTHONPATH'] = os.path.join(venv_libdir, python_ver, "site-packages") + ":" + break + + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) stdout, stderr = proc.communicate() if proc.returncode != 0: raise RuntimeError('%r failed (rc=%d) with output: %s' % (cmd, proc.returncode, stderr))