diff --git a/awx/main/expect/run.py b/awx/main/expect/run.py index 679cf709f3..601790757c 100755 --- a/awx/main/expect/run.py +++ b/awx/main/expect/run.py @@ -208,6 +208,12 @@ def run_isolated_job(private_data_dir, secrets, logfile=sys.stdout): env['AWX_ISOLATED_DATA_DIR'] = private_data_dir env['PYTHONPATH'] = env.get('PYTHONPATH', '') + callback_dir + ':' + venv_path = env.get('VIRTUAL_ENV') + if venv_path and not os.path.exists(venv_path): + raise RuntimeError( + 'a valid Python virtualenv does not exist at {}'.format(venv_path) + ) + return run_pexpect(args, cwd, env, logfile, expect_passwords=expect_passwords, idle_timeout=idle_timeout, diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 6dd14cce49..a355a28e41 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -761,12 +761,12 @@ class BaseTask(Task): os.chmod(path, stat.S_IRUSR) return path - def add_ansible_venv(self, venv_path, env, add_awx_lib=True): + def add_ansible_venv(self, venv_path, env, add_awx_lib=True, **kwargs): env['VIRTUAL_ENV'] = venv_path env['PATH'] = os.path.join(venv_path, "bin") + ":" + env['PATH'] venv_libdir = os.path.join(venv_path, "lib") - if not os.path.exists(venv_libdir): + if not kwargs.get('isolated', False) and not os.path.exists(venv_libdir): raise RuntimeError( 'a valid Python virtualenv does not exist at {}'.format(venv_path) ) @@ -1179,7 +1179,7 @@ class RunJob(BaseTask): plugin_dirs.extend(settings.AWX_ANSIBLE_CALLBACK_PLUGINS) plugin_path = ':'.join(plugin_dirs) env = super(RunJob, self).build_env(job, **kwargs) - env = self.add_ansible_venv(job.ansible_virtualenv_path, env, add_awx_lib=kwargs.get('isolated', False)) + env = self.add_ansible_venv(job.ansible_virtualenv_path, env, add_awx_lib=kwargs.get('isolated', False), **kwargs) # Set environment variables needed for inventory and job event # callbacks to work. env['JOB_ID'] = str(job.pk)