From fcc679489ea1e421cc22502fd8feb2ede2fcc33c Mon Sep 17 00:00:00 2001 From: beeankha Date: Tue, 11 Feb 2020 16:32:41 -0500 Subject: [PATCH] Update inventory_source module source_script parameter to be optional Unitied comment Fix up inventory_source example, misc comment edits --- awx_collection/plugins/modules/tower_group.py | 2 +- awx_collection/plugins/modules/tower_host.py | 2 +- .../plugins/modules/tower_inventory.py | 2 +- .../plugins/modules/tower_inventory_source.py | 28 +++++++++++-------- .../plugins/modules/tower_job_launch.py | 7 ----- .../plugins/modules/tower_organization.py | 1 + .../plugins/modules/tower_project.py | 1 + .../plugins/modules/tower_settings.py | 2 -- awx_collection/plugins/modules/tower_team.py | 2 +- awx_collection/plugins/modules/tower_user.py | 2 ++ 10 files changed, 24 insertions(+), 25 deletions(-) diff --git a/awx_collection/plugins/modules/tower_group.py b/awx_collection/plugins/modules/tower_group.py index ccfd7dc2bd..0dfa3845f0 100644 --- a/awx_collection/plugins/modules/tower_group.py +++ b/awx_collection/plugins/modules/tower_group.py @@ -111,7 +111,7 @@ def main(): if variables: variables = module.load_variables_if_file_specified(variables, 'variables') - # Create data to sent to create and update + # Create the data that gets sent for create and update group_fields = { 'name': new_name if new_name else name, 'inventory': inventory_id, diff --git a/awx_collection/plugins/modules/tower_host.py b/awx_collection/plugins/modules/tower_host.py index c416e020d6..4443b2ceff 100644 --- a/awx_collection/plugins/modules/tower_host.py +++ b/awx_collection/plugins/modules/tower_host.py @@ -125,7 +125,7 @@ def main(): } }) - # Create data to send to create and update + # Create the data that gets sent for create and update host_fields = { 'name': new_name if new_name else name, 'description': description, diff --git a/awx_collection/plugins/modules/tower_inventory.py b/awx_collection/plugins/modules/tower_inventory.py index e52771ec63..e0b7a4f0da 100644 --- a/awx_collection/plugins/modules/tower_inventory.py +++ b/awx_collection/plugins/modules/tower_inventory.py @@ -117,7 +117,7 @@ def main(): } }) - # Create the data sent to create and update + # Create the data that gets sent for create and update inventory_fields = { 'name': name, 'description': description, diff --git a/awx_collection/plugins/modules/tower_inventory_source.py b/awx_collection/plugins/modules/tower_inventory_source.py index f341f70d1b..9332ea125b 100644 --- a/awx_collection/plugins/modules/tower_inventory_source.py +++ b/awx_collection/plugins/modules/tower_inventory_source.py @@ -56,6 +56,7 @@ options: description: - Inventory script to be used when group type is C(custom). type: str + required: False source_vars: description: - The variables or environment fields to apply to this source type. @@ -130,13 +131,16 @@ extends_documentation_fragment: awx.awx.auth ''' EXAMPLES = ''' -- name: Add tower group - tower_group: - name: localhost - description: "Local Host Group" - inventory: "Local Inventory" - state: present - tower_config_file: "~/tower_cli.cfg" +- name: Add an inventory source + tower_inventory_source: + name: "source-inventory" + description: Source for inventory + inventory: previously-created-inventory + credential: previously-created-credential + overwrite: True + update_on_launch: True + source_vars: + private: false ''' from ..module_utils.tower_api import TowerModule @@ -157,7 +161,7 @@ def main(): "azure_rm", "vmware", "satellite6", "cloudforms", "openstack", "rhv", "tower", "custom"], required=False), source_path=dict(), - source_script=dict(), + source_script=dict(required=False), source_vars=dict(type='dict'), credential=dict(), source_regions=dict(), @@ -176,7 +180,7 @@ def main(): ) # One question here is do we want to end up supporting this within the ansible module itself (i.e. required if, etc) - # Or do we want to let the API return issues with "this dosen't support that", etc. + # Or do we want to let the API return issues with "this doesn't support that", etc. # # GUI OPTIONS: # - - - - - - - manual: file: scm: ec2: gce azure_rm vmware sat cloudforms openstack rhv tower custom @@ -323,7 +327,7 @@ def main(): if optional_vars['source_vars']: optional_vars['source_vars'] = dumps(optional_vars['source_vars']) - # Attempt to lookup the related items the user specified (these will fail the module if not found) + # Attempt to look up the related items the user specified (these will fail the module if not found) inventory_id = module.resolve_name_to_id('inventories', inventory) if credential: optional_vars['credential'] = module.resolve_name_to_id('credentials', credential) @@ -332,7 +336,7 @@ def main(): if source_script: optional_vars['source_script'] = module.resolve_name_to_id('inventory_scripts', source_script) - # Attempt to lookup team based on the provided name and org ID + # Attempt to look up inventory source based on the provided name and inventory ID inventory_source = module.get_one('inventory_sources', **{ 'data': { 'name': name, @@ -344,7 +348,7 @@ def main(): if state == 'present' and not inventory_source and not optional_vars['source']: module.fail_json(msg="If creating a new inventory source, the source param must be present") - # Create data to sent to create and update + # Create the data that gets sent for create and update inventory_source_fields = { 'name': new_name if new_name else name, 'inventory': inventory_id, diff --git a/awx_collection/plugins/modules/tower_job_launch.py b/awx_collection/plugins/modules/tower_job_launch.py index de1c8455d2..3ce7ecafc1 100644 --- a/awx_collection/plugins/modules/tower_job_launch.py +++ b/awx_collection/plugins/modules/tower_job_launch.py @@ -88,17 +88,11 @@ extends_documentation_fragment: awx.awx.auth ''' EXAMPLES = ''' -# Launch a job template - name: Launch a job tower_job_launch: job_template: "My Job Template" register: job -- name: Wait for job max 120s - tower_job_wait: - job_id: "{{ job.id }}" - timeout: 120 - - name: Launch a job template with extra_vars on remote Tower instance tower_job_launch: job_template: "My Job Template" @@ -108,7 +102,6 @@ EXAMPLES = ''' var3: "My Third Variable" job_type: run -# Launch job template with inventory and credential for prompt on launch - name: Launch a job with inventory and credential tower_job_launch: job_template: "My Job Template" diff --git a/awx_collection/plugins/modules/tower_organization.py b/awx_collection/plugins/modules/tower_organization.py index b91d30653a..2b0e4e925f 100644 --- a/awx_collection/plugins/modules/tower_organization.py +++ b/awx_collection/plugins/modules/tower_organization.py @@ -108,6 +108,7 @@ def main(): } }) + # Create the data that gets sent for create and update org_fields = {'name': name} if description: org_fields['description'] = description diff --git a/awx_collection/plugins/modules/tower_project.py b/awx_collection/plugins/modules/tower_project.py index c33235a523..6bb13dc3d2 100644 --- a/awx_collection/plugins/modules/tower_project.py +++ b/awx_collection/plugins/modules/tower_project.py @@ -232,6 +232,7 @@ def main(): } }) + # Create the data that gets sent for create and update project_fields = { 'name': name, 'description': description, diff --git a/awx_collection/plugins/modules/tower_settings.py b/awx_collection/plugins/modules/tower_settings.py index 8b73b1a212..67c88bd80a 100644 --- a/awx_collection/plugins/modules/tower_settings.py +++ b/awx_collection/plugins/modules/tower_settings.py @@ -46,8 +46,6 @@ options: extends_documentation_fragment: awx.awx.auth ''' -RETURN = ''' # ''' - EXAMPLES = ''' - name: Set the value of AWX_PROOT_BASE_PATH tower_settings: diff --git a/awx_collection/plugins/modules/tower_team.py b/awx_collection/plugins/modules/tower_team.py index 2f059d9eb5..1f14c38292 100644 --- a/awx_collection/plugins/modules/tower_team.py +++ b/awx_collection/plugins/modules/tower_team.py @@ -101,7 +101,7 @@ def main(): } }) - # Create data to sent to create and update + # Create the data that gets sent for create and update team_fields = { 'name': new_name if new_name else name, 'description': description, diff --git a/awx_collection/plugins/modules/tower_user.py b/awx_collection/plugins/modules/tower_user.py index 7c03e6c2f4..acbdf75891 100644 --- a/awx_collection/plugins/modules/tower_user.py +++ b/awx_collection/plugins/modules/tower_user.py @@ -128,6 +128,8 @@ def main(): # Extract our parameters state = module.params.get('state') + + # Create the data that gets sent for create and update user_fields = { 'username': module.params.get('username'), 'first_name': module.params.get('first_name'),