mirror of
https://github.com/ansible/awx.git
synced 2026-02-17 11:10:03 -03:30
Add ability to prompt for several variable types on launch
This commit is contained in:
@@ -2115,8 +2115,60 @@ class JobTemplateLaunch(RetrieveAPIView, GenericAPIView):
|
||||
kv = {
|
||||
'credential': serializer.instance.credential.pk,
|
||||
}
|
||||
|
||||
# -- following code will be moved to JobTemplate model --
|
||||
# Sort the runtime fields allowed and disallowed by job template
|
||||
ignored_fields = {}
|
||||
if 'extra_vars' in request.data:
|
||||
kv['extra_vars'] = request.data['extra_vars']
|
||||
kv['extra_vars'] = {}
|
||||
ignored_fields['extra_vars'] = {}
|
||||
if obj.ask_variables_on_launch:
|
||||
# Accept all extra_vars if the flag is set
|
||||
kv['extra_vars'] = request.data['extra_vars']
|
||||
else:
|
||||
if obj.survey_enabled:
|
||||
# Accept vars defined in the survey and no others
|
||||
survey_vars = [question['variable'] for question in obj.survey_spec['spec']]
|
||||
for key in request.data['extra_vars']:
|
||||
if key in survey_vars:
|
||||
kv['extra_vars'][key] = request.data['extra_vars'][key]
|
||||
else:
|
||||
ignored_fields['extra_vars'][key] = request.data['extra_vars'][key]
|
||||
else:
|
||||
# No survey & prompt flag is false - ignore all
|
||||
ignored_fields['extra_vars'] = request.data['extra_vars']
|
||||
|
||||
if 'limit' in request.data:
|
||||
if obj.ask_limit_on_launch:
|
||||
kv['limit'] = request.data['limit']
|
||||
else:
|
||||
ignored_fields['limit'] = request.data['limit']
|
||||
|
||||
if 'job_tags' or 'skip_tags' in request.data:
|
||||
if obj.ask_tags_on_launch:
|
||||
if 'job_tags' in request.data:
|
||||
kv['job_tags'] = request.data['job_tags']
|
||||
if 'skip_tags' in request.data:
|
||||
kv['skip_tags'] = request.data['skip_tags']
|
||||
else:
|
||||
if 'job_tags' in request.data:
|
||||
ignored_fields['job_tags'] = request.data['job_tags']
|
||||
if 'skip_tags' in request.data:
|
||||
ignored_fields['skip_tags'] = request.data['skip_tags']
|
||||
|
||||
if 'job_type' in request.data:
|
||||
if obj.ask_job_type_on_launch:
|
||||
kv['job_type'] = request.data['job_type']
|
||||
else:
|
||||
ignored_fields['job_type'] = request.data['job_type']
|
||||
|
||||
if 'inventory' in request.data:
|
||||
inv_id = request.data['inventory']
|
||||
if obj.ask_inventory_on_launch and Inventory.objects.get(pk=inv_id).accessible_by(self.request.user, {'write': True}):
|
||||
kv['inventory'] = inv_id
|
||||
else:
|
||||
ignored_fields['inventory'] = inv_id
|
||||
|
||||
kv.update(passwords)
|
||||
|
||||
new_job = obj.create_unified_job(**kv)
|
||||
@@ -2127,6 +2179,9 @@ class JobTemplateLaunch(RetrieveAPIView, GenericAPIView):
|
||||
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
||||
else:
|
||||
data = dict(job=new_job.id)
|
||||
serializer = JobSerializer(new_job)
|
||||
data['job_data'] = serializer.data
|
||||
data['ignored_fields'] = ignored_fields
|
||||
return Response(data, status=status.HTTP_202_ACCEPTED)
|
||||
|
||||
class JobTemplateSchedulesList(SubListCreateAttachDetachAPIView):
|
||||
|
||||
Reference in New Issue
Block a user