From 8a09731a528088b7a9b5a8f937ce32a01e8f5da5 Mon Sep 17 00:00:00 2001 From: Anton Nesterov Date: Wed, 7 Oct 2020 22:08:46 +0200 Subject: [PATCH] Rename inventory_source param to name * fixes #8347 * Rename inventory_source to name in the tower_inventory_source_update * Allow to specify both name or id for `name` and `inventory` params --- .../modules/tower_inventory_source_update.py | 28 +++++++++---------- .../tasks/main.yml | 4 +-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/awx_collection/plugins/modules/tower_inventory_source_update.py b/awx_collection/plugins/modules/tower_inventory_source_update.py index 945cd304b5..af01caee91 100644 --- a/awx_collection/plugins/modules/tower_inventory_source_update.py +++ b/awx_collection/plugins/modules/tower_inventory_source_update.py @@ -22,14 +22,14 @@ description: - Update Ansible Tower inventory source(s). See U(https://www.ansible.com/tower) for an overview. options: - inventory: + name: description: - - Name of the inventory that contains the inventory source(s) to update. + - The name or id of the inventory source to update. required: True type: str - inventory_source: + inventory: description: - - The name of the inventory source to update. + - Name or id of the inventory that contains the inventory source(s) to update. required: True type: str organization: @@ -58,14 +58,14 @@ extends_documentation_fragment: awx.awx.auth EXAMPLES = ''' - name: Update a single inventory source tower_inventory_source_update: + name: "Example Inventory Source" inventory: "My Inventory" - inventory_source: "Example Inventory Source" organization: Default - name: Update all inventory sources tower_inventory_source_update: + name: "{{ item }}" inventory: "My Other Inventory" - inventory_source: "{{ item }}" loop: "{{ query('awx.awx.tower_api', 'inventory_sources', query_params={ 'inventory': 30 }, return_ids=True ) }}" ''' @@ -88,8 +88,8 @@ from ..module_utils.tower_api import TowerAPIModule def main(): # Any additional arguments that are not fields of the item can be added here argument_spec = dict( + name=dict(required=True), inventory=dict(required=True), - inventory_source=dict(required=True), organization=dict(), wait=dict(default=False, type='bool'), interval=dict(default=1.0, type='float'), @@ -100,8 +100,8 @@ def main(): module = TowerAPIModule(argument_spec=argument_spec) # Extract our parameters + name = module.params.get('name') inventory = module.params.get('inventory') - inventory_source = module.params.get('inventory_source') organization = module.params.get('organization') wait = module.params.get('wait') interval = module.params.get('interval') @@ -115,20 +115,18 @@ def main(): if not inventory_object: module.fail_json(msg='The specified inventory, {0}, was not found.'.format(lookup_data)) - inventory_source_object = module.get_one('inventory_sources', name_or_id=inventory_source, **{ - 'data': { - 'inventory': inventory_object['id'], - } - }) + inventory_source_object = module.get_one('inventory_sources', + name_or_id=name, + data={'inventory': inventory_object['id']}) if not inventory_source_object: module.fail_json(msg='The specified inventory source was not found.') # Sync the inventory source(s) - inventory_source_update_results = module.post_endpoint(inventory_source_object['related']['update'], **{'data': {}}) + inventory_source_update_results = module.post_endpoint(inventory_source_object['related']['update']) if inventory_source_update_results['status_code'] != 202: - module.fail_json(msg="Failed to update inventory source, see response for details", **{'response': inventory_source_update_results}) + module.fail_json(msg="Failed to update inventory source, see response for details", response=inventory_source_update_results) module.json_output['changed'] = True module.json_output['id'] = inventory_source_update_results['json']['id'] diff --git a/awx_collection/tests/integration/targets/tower_inventory_source_update/tasks/main.yml b/awx_collection/tests/integration/targets/tower_inventory_source_update/tasks/main.yml index 36a4e4b058..afb1bd962f 100644 --- a/awx_collection/tests/integration/targets/tower_inventory_source_update/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_inventory_source_update/tasks/main.yml @@ -73,8 +73,8 @@ - name: Test Inventory Source Update tower_inventory_source_update: + name: "{{ inv_source2 }}" inventory: "{{ inv_name }}" - inventory_source: "{{ inv_source2 }}" organization: Default register: result @@ -84,8 +84,8 @@ - name: Test Inventory Source Update for All Sources tower_inventory_source_update: + name: "{{ item.name }}" inventory: "{{ inv_name }}" - inventory_source: "{{ item.name }}" organization: Default wait: true loop: "{{ query('awx.awx.tower_api', 'inventory_sources', query_params={ 'inventory': created_inventory.id }, expect_objects=True, return_objects=True) }}"