From e22967d28de40fe40d94fd4818aa9248942f6b4c Mon Sep 17 00:00:00 2001 From: Hao Liu Date: Mon, 6 Feb 2023 14:09:05 -0500 Subject: [PATCH] add constructed kind to inventory module - add kind 'constructed' to inventory module - add 'input_inventories' field to inventory module Co-authored-by: Rick Elrod Signed-off-by: Rick Elrod --- awx_collection/plugins/modules/inventory.py | 17 +++++++++++++++-- awx_collection/test/awx/test_completeness.py | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/awx_collection/plugins/modules/inventory.py b/awx_collection/plugins/modules/inventory.py index 8e739b2211..3a479bcd03 100644 --- a/awx_collection/plugins/modules/inventory.py +++ b/awx_collection/plugins/modules/inventory.py @@ -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, diff --git a/awx_collection/test/awx/test_completeness.py b/awx_collection/test/awx/test_completeness.py index ef3d70727a..b4eb0ad3e4 100644 --- a/awx_collection/test/awx/test_completeness.py +++ b/awx_collection/test/awx/test_completeness.py @@ -20,7 +20,9 @@ read_only_endpoints_with_modules = ['settings', 'role', 'project_update', 'workf # 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_inventory', # 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 = [