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
This commit is contained in:
Anton Nesterov 2020-10-07 22:08:46 +02:00
parent 28e792056d
commit 8a09731a52
2 changed files with 15 additions and 17 deletions

View File

@ -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']

View File

@ -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) }}"