From e642af82ccb7dcea942532dff2133e6e49dbebd9 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Fri, 26 Jan 2018 13:46:48 -0500 Subject: [PATCH] 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 --- awx/main/models/unified_jobs.py | 2 ++ awx/main/tasks.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index 97a03d6845..c2a74adfc8 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -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 diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 11c2772c87..1f74fb04a1 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -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