Repository: ansible/awx

Issue:
collection module tower_inventory_source_update should have "name" instead of "inventory_source"
<!-- Issues are for **concrete, actionable bugs and feature requests** only - if you're just asking for debugging help or technical support, please use:

- http://webchat.freenode.net/?channels=ansible-awx
- https://groups.google.com/forum/#!forum/awx-project

We have to limit this because of limited volunteer time to respond to issues! -->

##### ISSUE TYPE
 - Feature Idea

##### SUMMARY
<!-- Briefly describe the problem or desired enhancement. -->
Module that works on an entity should reference that entity by `name`. It feels more ansibly anyway.


Discussion:

Resolving patch:
diff --git a/awx_collection/plugins/modules/tower_inventory_source_update.py b/awx_collection/plugins/modules/tower_inventory_source_update.py
--- a/awx_collection/plugins/modules/tower_inventory_source_update.py
+++ b/awx_collection/plugins/modules/tower_inventory_source_update.py
@@ -22,14 +22,16 @@
     - 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:
+      aliases:
+        - 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 +60,14 @@
 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 +90,8 @@
 def main():
     # Any additional arguments that are not fields of the item can be added here
     argument_spec = dict(
+        name=dict(required=True, aliases=['inventory_source']),
         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 +102,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 +117,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']


Test patch:
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
--- 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,23 @@
 
     - name: Test Inventory Source Update for All Sources
       tower_inventory_source_update:
+        name: "{{ item.name }}"
         inventory: "{{ inv_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) }}"
+      loop_control:
+        label: "{{ item.name }}"
+      register: result
+
+    - assert:
+        that:
+          - "result is changed"
+
+    - name: Test Inventory Source Update for All Sources (using inventory_source as alias for name)
+      tower_inventory_source_update:
         inventory_source: "{{ item.name }}"
+        inventory: "{{ inv_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) }}"