1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

show a better error when a custom venv doesn't exist on an isolated node

see: https://github.com/ansible/tower/issues/2852
This commit is contained in:
Ryan Petrello 2018-08-15 12:56:40 -04:00
parent b690e61576
commit 5f6907ba83
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
2 changed files with 9 additions and 3 deletions

View File

@ -208,6 +208,12 @@ def run_isolated_job(private_data_dir, secrets, logfile=sys.stdout):
env['AWX_ISOLATED_DATA_DIR'] = private_data_dir env['AWX_ISOLATED_DATA_DIR'] = private_data_dir
env['PYTHONPATH'] = env.get('PYTHONPATH', '') + callback_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, return run_pexpect(args, cwd, env, logfile,
expect_passwords=expect_passwords, expect_passwords=expect_passwords,
idle_timeout=idle_timeout, idle_timeout=idle_timeout,

View File

@ -761,12 +761,12 @@ class BaseTask(Task):
os.chmod(path, stat.S_IRUSR) os.chmod(path, stat.S_IRUSR)
return path 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['VIRTUAL_ENV'] = venv_path
env['PATH'] = os.path.join(venv_path, "bin") + ":" + env['PATH'] env['PATH'] = os.path.join(venv_path, "bin") + ":" + env['PATH']
venv_libdir = os.path.join(venv_path, "lib") 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( raise RuntimeError(
'a valid Python virtualenv does not exist at {}'.format(venv_path) '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_dirs.extend(settings.AWX_ANSIBLE_CALLBACK_PLUGINS)
plugin_path = ':'.join(plugin_dirs) plugin_path = ':'.join(plugin_dirs)
env = super(RunJob, self).build_env(job, **kwargs) 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 # Set environment variables needed for inventory and job event
# callbacks to work. # callbacks to work.
env['JOB_ID'] = str(job.pk) env['JOB_ID'] = str(job.pk)