From 2b5ff9a6f992a3c8b3e494735e6e38665c7e9a9b Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Wed, 11 Mar 2020 11:39:27 -0400 Subject: [PATCH] Patches to generator to better align with modules --- awx_collection/plugins/modules/tower_user.py | 7 +++---- awx_collection/tools/generate.yml | 2 +- .../tools/templates/tower_module.j2 | 20 ++++--------------- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/awx_collection/plugins/modules/tower_user.py b/awx_collection/plugins/modules/tower_user.py index ecddbc42c0..d052f8fa3a 100644 --- a/awx_collection/plugins/modules/tower_user.py +++ b/awx_collection/plugins/modules/tower_user.py @@ -45,7 +45,7 @@ options: type: str is_superuser: description: - - User is a system wide administrator. + - Designates that this user has all permissions without explicitly assigning them. required: False type: bool default: False @@ -59,10 +59,9 @@ options: aliases: ['auditor'] password: description: - - Password of the user; write-only field. + - Write-only field used to change the password. required: False type: str - default: '' state: description: - Desired state of the resource. @@ -128,7 +127,7 @@ def main(): email=dict(required=False, type='str'), is_superuser=dict(required=False, type='bool', default=False, aliases=['superuser']), is_system_auditor=dict(required=False, type='bool', default=False, aliases=['auditor']), - password=dict(required=False, type='str', default=''), + password=dict(required=False, type='str'), state=dict(choices=['present', 'absent'], default='present'), ) diff --git a/awx_collection/tools/generate.yml b/awx_collection/tools/generate.yml index e5e98484f8..20f86bbf85 100644 --- a/awx_collection/tools/generate.yml +++ b/awx_collection/tools/generate.yml @@ -57,7 +57,7 @@ - name: Process endpoint template: src: "templates/tower_module.j2" - dest: "modules/{{ file_name }}" + dest: "{{ playbook_dir | dirname }}/plugins/modules/{{ file_name }}" loop: "{{ end_point_options['results'] }}" loop_control: label: "{{ item['item']['key'] }}" diff --git a/awx_collection/tools/templates/tower_module.j2 b/awx_collection/tools/templates/tower_module.j2 index bed690f9c5..5592b14eb8 100644 --- a/awx_collection/tools/templates/tower_module.j2 +++ b/awx_collection/tools/templates/tower_module.j2 @@ -41,8 +41,8 @@ options: {% endif %} required: {{ item['json']['actions']['POST'][option]['required'] }} type: {{ type_map[ item['json']['actions']['POST'][option]['type'] ] }} -{% if 'default' in item['json']['actions']['POST'][option] %} - default: '{{ item['json']['actions']['POST'][option]['default'] }}' +{% if item['json']['actions']['POST'][option].get('default', '') != '' %} + default: {{ item['json']['actions']['POST'][option]['default'] }} {% endif %} {% if 'choices' in item['json']['actions']['POST'][option] %} choices: @@ -94,7 +94,7 @@ def main(): {% for option in item['json']['actions']['POST'] %} {% set option_data = [] %} {{ option_data.append('required={}'.format(item['json']['actions']['POST'][option]['required'])) -}} -{{ option_data.append('type={}'.format(type_map[item['json']['actions']['POST'][option]['type']])) -}} +{{ option_data.append('type=\'{}\''.format(type_map[item['json']['actions']['POST'][option]['type']])) -}} {% if item['json']['actions']['POST'][option]['type'] == 'password' %} {{ option_data.append('no_log=True') -}} {% endif %} @@ -105,7 +105,7 @@ def main(): {% endfor %} {{ option_data.append('choices=[{}]'.format(all_choices | join(', '))) -}} {% endif %} -{% if 'default' in item['json']['actions']['POST'][option] %} +{% if item['json']['actions']['POST'][option].get('default', '') != '' %} {{ option_data.append("default='{}'".format(item['json']['actions']['POST'][option]['default'])) -}} {% endif %} {% if aliases[item_type][option] | default(False) %} @@ -129,18 +129,6 @@ def main(): # Extract our parameters {% for option in item['json']['actions']['POST'] %} {{ option }} = module.params.get('{{ option }}') -{% if 'min_value' in item['json']['actions']['POST'][option] %} - if {{ option }} < {{ item['json']['actions']['POST'][option]['min_value'] }}: - module.fail_msg(msg="The value for {{ option }} can not be less than {{ item['json']['actions']['POST'][option]['min_value'] }}") -{% endif %} -{% if 'max_value' in item['json']['actions']['POST'][option] %} - if {{ option }} > {{ item['json']['actions']['POST'][option]['max_value'] }}: - module.fail_msg(msg="The value for {{ option }} can not be larger than {{ item['json']['actions']['POST'][option]['max_value'] }}") -{% endif %} -{% if 'max_length' in item['json']['actions']['POST'][option] %} - if {{ option }} and len({{ option }}) > {{ item['json']['actions']['POST'][option]['max_length'] }}: - module.fail_msg(msg="The value for {{ option }} can not be longer than {{ item['json']['actions']['POST'][option]['max_length'] }}") -{% endif %} {% if option == name_option %} new_{{ name_option }} = module.params.get("new_{{ name_option }}") {% endif %}