Merge pull request #13525 from TheRealHaoLiu/inventory-module-update

[constructed-inventory] add 'constructed' kind to inventory module for awx-collection
This commit is contained in:
Hao Liu 2023-02-06 14:40:12 -05:00 committed by GitHub
commit 280ceae267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -54,7 +54,7 @@ options:
kind:
description:
- The kind field. Cannot be modified after created.
choices: ["", "smart"]
choices: ["", "smart", "constructed"]
type: str
host_filter:
description:
@ -65,6 +65,11 @@ options:
- list of Instance Groups for this Organization to run on.
type: list
elements: str
input_inventories:
description:
- List of Inventories to use as input for Constructed Inventory.
type: list
elements: str
prevent_instance_group_fallback:
description:
- Prevent falling back to instance groups set on the organization
@ -111,11 +116,12 @@ def main():
description=dict(),
organization=dict(required=True),
variables=dict(type='dict'),
kind=dict(choices=['', 'smart']),
kind=dict(choices=['', 'smart', 'constructed']),
host_filter=dict(),
instance_groups=dict(type="list", elements='str'),
prevent_instance_group_fallback=dict(type='bool'),
state=dict(choices=['present', 'absent'], default='present'),
input_inventories=dict(type='list', elements='str'),
)
# Create a module for ourselves
@ -181,6 +187,13 @@ def main():
if inventory and inventory['kind'] == '' and inventory_fields['kind'] == 'smart':
module.fail_json(msg='You cannot turn a regular inventory into a "smart" inventory.')
if kind == 'constructed':
input_inventory_names = module.params.get('input_inventories')
if input_inventory_names is not None:
association_fields['input_inventories'] = []
for item in input_inventory_names:
association_fields['input_inventories'].append(module.resolve_name_to_id('inventories', item))
# If the state was present and we can let the module build or update the existing inventory, this will return on its own
module.create_or_update_if_needed(
inventory,

View File

@ -20,7 +20,9 @@ read_only_endpoints_with_modules = ['settings', 'role', 'project_update']
# If a module should not be created for an endpoint and the endpoint is not read-only add it here
# THINK HARD ABOUT DOING THIS
no_module_for_endpoint = []
no_module_for_endpoint = [
'constructed_inventories', # This is a view for inventory with kind=constructed
]
# Some modules work on the related fields of an endpoint. These modules will not have an auto-associated endpoint
no_endpoint_for_module = [