mirror of
https://github.com/ansible/awx.git
synced 2026-02-17 19:20:05 -03:30
Refactor job template callback post to mimic the behavior of normal jt launch.
This commit is contained in:
@@ -2727,14 +2727,14 @@ class JobTemplateCallback(GenericAPIView):
|
|||||||
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
# Everything is fine; actually create the job.
|
# Everything is fine; actually create the job.
|
||||||
|
kv = {"limit": limit, "launch_type": 'callback'}
|
||||||
|
if extra_vars is not None and job_template.ask_variables_on_launch:
|
||||||
|
kv['extra_vars'] = callback_filter_out_ansible_extra_vars(extra_vars)
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
job = job_template.create_job(limit=limit, launch_type='callback')
|
job = job_template.create_job(**kv)
|
||||||
|
|
||||||
# Send a signal to celery that the job should be started.
|
# Send a signal to celery that the job should be started.
|
||||||
kv = {"inventory_sources_already_updated": inventory_sources_already_updated}
|
result = job.signal_start(inventory_sources_already_updated=inventory_sources_already_updated)
|
||||||
if extra_vars is not None:
|
|
||||||
kv['extra_vars'] = callback_filter_out_ansible_extra_vars(extra_vars)
|
|
||||||
result = job.signal_start(**kv)
|
|
||||||
if not result:
|
if not result:
|
||||||
data = dict(msg=_('Error starting job!'))
|
data = dict(msg=_('Error starting job!'))
|
||||||
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|||||||
@@ -300,6 +300,8 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, Resour
|
|||||||
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.
|
||||||
'''
|
'''
|
||||||
|
# It is worthwhile to find out if this function is now only used by
|
||||||
|
# provisioning callback.
|
||||||
variables_needed = False
|
variables_needed = False
|
||||||
if callback_extra_vars:
|
if callback_extra_vars:
|
||||||
extra_vars_dict = parse_yaml_or_json(callback_extra_vars)
|
extra_vars_dict = parse_yaml_or_json(callback_extra_vars)
|
||||||
@@ -310,10 +312,13 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, Resour
|
|||||||
elif self.variables_needed_to_start:
|
elif self.variables_needed_to_start:
|
||||||
variables_needed = True
|
variables_needed = True
|
||||||
prompting_needed = False
|
prompting_needed = False
|
||||||
for key, value in self._ask_for_vars_dict().iteritems():
|
# The behavior of provisioning callback should mimic
|
||||||
if value and not (key == 'extra_vars' and
|
# that of job template launch, so prompting_needed should
|
||||||
callback_extra_vars is not None):
|
# not block a provisioning callback from creating/launching jobs.
|
||||||
prompting_needed = True
|
if callback_extra_vars is None:
|
||||||
|
for value in self._ask_for_vars_dict().values():
|
||||||
|
if value:
|
||||||
|
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 variables_needed)
|
not variables_needed)
|
||||||
|
|||||||
Reference in New Issue
Block a user