mirror of
https://github.com/ansible/awx.git
synced 2026-03-03 01:38:50 -03:30
allow JT start on callback if mandatory survey variables are there
This commit is contained in:
@@ -2702,7 +2702,7 @@ class JobTemplateCallback(GenericAPIView):
|
|||||||
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
||||||
else:
|
else:
|
||||||
host = list(matching_hosts)[0]
|
host = list(matching_hosts)[0]
|
||||||
if not job_template.can_start_without_user_input():
|
if not job_template.can_start_without_user_input(callback_extra_vars=extra_vars):
|
||||||
data = dict(msg=_('Cannot start automatically, user input required!'))
|
data = dict(msg=_('Cannot start automatically, user input required!'))
|
||||||
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
||||||
limit = host.name
|
limit = host.name
|
||||||
|
|||||||
@@ -295,18 +295,27 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, Resour
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('api:job_template_detail', args=(self.pk,))
|
return reverse('api:job_template_detail', args=(self.pk,))
|
||||||
|
|
||||||
def can_start_without_user_input(self):
|
def can_start_without_user_input(self, callback_extra_vars=None):
|
||||||
'''
|
'''
|
||||||
Return whether job template can be used to start a new job without
|
Return whether job template can be used to start a new job without
|
||||||
requiring any user input.
|
requiring any user input.
|
||||||
'''
|
'''
|
||||||
|
variables_needed = False
|
||||||
|
if callback_extra_vars:
|
||||||
|
extra_vars_dict = parse_yaml_or_json(callback_extra_vars)
|
||||||
|
for var in self.variables_needed_to_start:
|
||||||
|
if var not in extra_vars_dict:
|
||||||
|
variables_needed = True
|
||||||
|
break
|
||||||
|
elif self.variables_needed_to_start:
|
||||||
|
variables_needed = True
|
||||||
prompting_needed = False
|
prompting_needed = False
|
||||||
for value in self._ask_for_vars_dict().values():
|
for value in self._ask_for_vars_dict().values():
|
||||||
if value:
|
if value:
|
||||||
prompting_needed = True
|
prompting_needed = True
|
||||||
return (not prompting_needed and
|
return (not prompting_needed and
|
||||||
not self.passwords_needed_to_start and
|
not self.passwords_needed_to_start and
|
||||||
not self.variables_needed_to_start)
|
not variables_needed)
|
||||||
|
|
||||||
def _ask_for_vars_dict(self):
|
def _ask_for_vars_dict(self):
|
||||||
return dict(
|
return dict(
|
||||||
|
|||||||
Reference in New Issue
Block a user