mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 18:37:36 -02:30
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:
@@ -22,14 +22,14 @@ description:
|
|||||||
- Update Ansible Tower inventory source(s). See
|
- Update Ansible Tower inventory source(s). See
|
||||||
U(https://www.ansible.com/tower) for an overview.
|
U(https://www.ansible.com/tower) for an overview.
|
||||||
options:
|
options:
|
||||||
inventory:
|
name:
|
||||||
description:
|
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
|
required: True
|
||||||
type: str
|
type: str
|
||||||
inventory_source:
|
inventory:
|
||||||
description:
|
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
|
required: True
|
||||||
type: str
|
type: str
|
||||||
organization:
|
organization:
|
||||||
@@ -58,14 +58,14 @@ extends_documentation_fragment: awx.awx.auth
|
|||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: Update a single inventory source
|
- name: Update a single inventory source
|
||||||
tower_inventory_source_update:
|
tower_inventory_source_update:
|
||||||
|
name: "Example Inventory Source"
|
||||||
inventory: "My Inventory"
|
inventory: "My Inventory"
|
||||||
inventory_source: "Example Inventory Source"
|
|
||||||
organization: Default
|
organization: Default
|
||||||
|
|
||||||
- name: Update all inventory sources
|
- name: Update all inventory sources
|
||||||
tower_inventory_source_update:
|
tower_inventory_source_update:
|
||||||
|
name: "{{ item }}"
|
||||||
inventory: "My Other Inventory"
|
inventory: "My Other Inventory"
|
||||||
inventory_source: "{{ item }}"
|
|
||||||
loop: "{{ query('awx.awx.tower_api', 'inventory_sources', query_params={ 'inventory': 30 }, return_ids=True ) }}"
|
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():
|
def main():
|
||||||
# Any additional arguments that are not fields of the item can be added here
|
# Any additional arguments that are not fields of the item can be added here
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
|
name=dict(required=True),
|
||||||
inventory=dict(required=True),
|
inventory=dict(required=True),
|
||||||
inventory_source=dict(required=True),
|
|
||||||
organization=dict(),
|
organization=dict(),
|
||||||
wait=dict(default=False, type='bool'),
|
wait=dict(default=False, type='bool'),
|
||||||
interval=dict(default=1.0, type='float'),
|
interval=dict(default=1.0, type='float'),
|
||||||
@@ -100,8 +100,8 @@ def main():
|
|||||||
module = TowerAPIModule(argument_spec=argument_spec)
|
module = TowerAPIModule(argument_spec=argument_spec)
|
||||||
|
|
||||||
# Extract our parameters
|
# Extract our parameters
|
||||||
|
name = module.params.get('name')
|
||||||
inventory = module.params.get('inventory')
|
inventory = module.params.get('inventory')
|
||||||
inventory_source = module.params.get('inventory_source')
|
|
||||||
organization = module.params.get('organization')
|
organization = module.params.get('organization')
|
||||||
wait = module.params.get('wait')
|
wait = module.params.get('wait')
|
||||||
interval = module.params.get('interval')
|
interval = module.params.get('interval')
|
||||||
@@ -115,20 +115,18 @@ def main():
|
|||||||
if not inventory_object:
|
if not inventory_object:
|
||||||
module.fail_json(msg='The specified inventory, {0}, was not found.'.format(lookup_data))
|
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, **{
|
inventory_source_object = module.get_one('inventory_sources',
|
||||||
'data': {
|
name_or_id=name,
|
||||||
'inventory': inventory_object['id'],
|
data={'inventory': inventory_object['id']})
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if not inventory_source_object:
|
if not inventory_source_object:
|
||||||
module.fail_json(msg='The specified inventory source was not found.')
|
module.fail_json(msg='The specified inventory source was not found.')
|
||||||
|
|
||||||
# Sync the inventory source(s)
|
# 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:
|
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['changed'] = True
|
||||||
module.json_output['id'] = inventory_source_update_results['json']['id']
|
module.json_output['id'] = inventory_source_update_results['json']['id']
|
||||||
|
|||||||
@@ -73,8 +73,8 @@
|
|||||||
|
|
||||||
- name: Test Inventory Source Update
|
- name: Test Inventory Source Update
|
||||||
tower_inventory_source_update:
|
tower_inventory_source_update:
|
||||||
|
name: "{{ inv_source2 }}"
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
inventory_source: "{{ inv_source2 }}"
|
|
||||||
organization: Default
|
organization: Default
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
@@ -84,8 +84,8 @@
|
|||||||
|
|
||||||
- name: Test Inventory Source Update for All Sources
|
- name: Test Inventory Source Update for All Sources
|
||||||
tower_inventory_source_update:
|
tower_inventory_source_update:
|
||||||
|
name: "{{ item.name }}"
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
inventory_source: "{{ item.name }}"
|
|
||||||
organization: Default
|
organization: Default
|
||||||
wait: true
|
wait: true
|
||||||
loop: "{{ query('awx.awx.tower_api', 'inventory_sources', query_params={ 'inventory': created_inventory.id }, expect_objects=True, return_objects=True) }}"
|
loop: "{{ query('awx.awx.tower_api', 'inventory_sources', query_params={ 'inventory': created_inventory.id }, expect_objects=True, return_objects=True) }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user