Make org an optional parameter for both inv source and inv source update modules

This commit is contained in:
beeankha
2020-09-04 18:40:18 -04:00
parent 4133ec974b
commit a0b8f6a25d
6 changed files with 40 additions and 37 deletions

View File

@@ -131,7 +131,6 @@ options:
organization:
description:
- Name of the inventory source's inventory's organization.
required: True
type: str
extends_documentation_fragment: awx.awx.auth
'''
@@ -174,7 +173,7 @@ def main():
enabled_value=dict(),
host_filter=dict(),
credential=dict(),
organization=dict(required=True),
organization=dict(),
overwrite=dict(type='bool'),
overwrite_vars=dict(type='bool'),
custom_virtualenv=dict(),
@@ -203,14 +202,10 @@ def main():
source_project = module.params.get('source_project')
state = module.params.get('state')
# Attempt to look up inventory source based on the provided name and inventory ID
org_id = module.resolve_name_to_id('organizations', organization)
inventory_object = module.get_one('inventories', **{
'data': {
'name': inventory,
'organization': org_id,
}
})
lookup_data = {'name': inventory}
if organization:
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
inventory_object = module.get_one('inventories', data=lookup_data)
if not inventory_object:
module.fail_json(msg='The specified inventory was not found.')

View File

@@ -36,7 +36,6 @@ options:
description:
- Name of the inventory source's inventory's organization.
type: str
required: True
wait:
description:
- Wait for the job to complete.
@@ -91,7 +90,7 @@ def main():
argument_spec = dict(
inventory=dict(required=True),
inventory_source=dict(required=True),
organization=dict(required=True),
organization=dict(),
wait=dict(default=False, type='bool'),
interval=dict(default=1.0, type='float'),
timeout=dict(default=None, type='int'),
@@ -108,13 +107,10 @@ def main():
interval = module.params.get('interval')
timeout = module.params.get('timeout')
org_id = module.resolve_name_to_id('organizations', organization)
inventory_object = module.get_one('inventories', **{
'data': {
'name': inventory,
'organization': org_id,
}
})
lookup_data = {'name': inventory}
if organization:
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
inventory_object = module.get_one('inventories', data=lookup_data)
if not inventory_object:
module.fail_json(msg='The specified inventory was not found.')