fix a few bugs for scheduled jobs that run without inventories

see: https://github.com/ansible/ansible-tower/issues/7865
see: https://github.com/ansible/ansible-tower/issues/7866
This commit is contained in:
Ryan Petrello 2018-01-26 13:46:48 -05:00
parent b0a755d7b5
commit e642af82cc
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
2 changed files with 6 additions and 0 deletions

View File

@ -1119,6 +1119,8 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
def can_schedule(self):
if getattr(self, 'passwords_needed_to_start', None):
return False
if getattr(self, 'inventory', None) is None:
return False
JobLaunchConfig = self._meta.get_field('launch_config').related_model
try:
self.launch_config

View File

@ -1178,6 +1178,10 @@ class RunJob(BaseTask):
return getattr(settings, 'AWX_PROOT_ENABLED', False)
def pre_run_hook(self, job, **kwargs):
if job.inventory is None:
error = _('Job could not start because it does not have a valid inventory.')
self.update_model(job.pk, status='failed', job_explanation=error)
raise RuntimeError(error)
if job.project and job.project.scm_type:
job_request_id = '' if self.request.id is None else self.request.id
pu_ig = job.instance_group