From 357e22eb5120673efada94f1a3983a1d9ced71ac Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Tue, 17 Mar 2020 15:48:24 -0400 Subject: [PATCH] Compensating for default of '' for a JSON typed field --- awx_collection/tools/templates/tower_module.j2 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/awx_collection/tools/templates/tower_module.j2 b/awx_collection/tools/templates/tower_module.j2 index 5f728b6229..bdba4bd20e 100644 --- a/awx_collection/tools/templates/tower_module.j2 +++ b/awx_collection/tools/templates/tower_module.j2 @@ -41,8 +41,13 @@ options: {% endif %} required: {{ item['json']['actions']['POST'][option]['required'] }} type: {{ type_map[ item['json']['actions']['POST'][option]['type'] ] }} -{% if item['json']['actions']['POST'][option].get('default', '') != '' %} - default: {{ item['json']['actions']['POST'][option]['default'] }} +{% if 'default' in item['json']['actions']['POST'][option] %} +{# for tower_job_template/extra vars, its type is dict but its default is '', so we want to make that {} #} +{% if item['json']['actions']['POST'][option]['default'] == '' and type_map[ item['json']['actions']['POST'][option]['type'] ] == 'dict' %} + default: {} +{% else %} + default: '{{ item['json']['actions']['POST'][option]['default'] }}' +{% endif %} {% endif %} {% if 'choices' in item['json']['actions']['POST'][option] %} choices: @@ -106,7 +111,11 @@ def main(): {{ option_data.append('choices=[{}]'.format(all_choices | join(', '))) -}} {% endif %} {% if item['json']['actions']['POST'][option].get('default', '') != '' %} -{{ option_data.append("default='{}'".format(item['json']['actions']['POST'][option]['default'])) -}} +{% set default_value = item['json']['actions']['POST'][option]['default'] %} +{% if item['json']['actions']['POST'][option]['default'] == '' and type_map[ item['json']['actions']['POST'][option]['type'] ] == 'dict' %} +{% set default_value = '{}' %} +{% endif %} +{{ option_data.append("default='{}'".format(default_value)) -}} {% endif %} {% if aliases[item_type][option] | default(False) %} {% set alias_list = [] %}