mirror of
https://github.com/ansible/awx.git
synced 2026-02-25 23:16:01 -03:30
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:
@@ -54,7 +54,7 @@ options:
|
|||||||
kind:
|
kind:
|
||||||
description:
|
description:
|
||||||
- The kind field. Cannot be modified after created.
|
- The kind field. Cannot be modified after created.
|
||||||
choices: ["", "smart"]
|
choices: ["", "smart", "constructed"]
|
||||||
type: str
|
type: str
|
||||||
host_filter:
|
host_filter:
|
||||||
description:
|
description:
|
||||||
@@ -65,6 +65,11 @@ options:
|
|||||||
- list of Instance Groups for this Organization to run on.
|
- list of Instance Groups for this Organization to run on.
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
|
input_inventories:
|
||||||
|
description:
|
||||||
|
- List of Inventories to use as input for Constructed Inventory.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
prevent_instance_group_fallback:
|
prevent_instance_group_fallback:
|
||||||
description:
|
description:
|
||||||
- Prevent falling back to instance groups set on the organization
|
- Prevent falling back to instance groups set on the organization
|
||||||
@@ -111,11 +116,12 @@ def main():
|
|||||||
description=dict(),
|
description=dict(),
|
||||||
organization=dict(required=True),
|
organization=dict(required=True),
|
||||||
variables=dict(type='dict'),
|
variables=dict(type='dict'),
|
||||||
kind=dict(choices=['', 'smart']),
|
kind=dict(choices=['', 'smart', 'constructed']),
|
||||||
host_filter=dict(),
|
host_filter=dict(),
|
||||||
instance_groups=dict(type="list", elements='str'),
|
instance_groups=dict(type="list", elements='str'),
|
||||||
prevent_instance_group_fallback=dict(type='bool'),
|
prevent_instance_group_fallback=dict(type='bool'),
|
||||||
state=dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
|
input_inventories=dict(type='list', elements='str'),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a module for ourselves
|
# Create a module for ourselves
|
||||||
@@ -181,6 +187,13 @@ def main():
|
|||||||
if inventory and inventory['kind'] == '' and inventory_fields['kind'] == 'smart':
|
if inventory and inventory['kind'] == '' and inventory_fields['kind'] == 'smart':
|
||||||
module.fail_json(msg='You cannot turn a regular inventory into a "smart" inventory.')
|
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
|
# 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(
|
module.create_or_update_if_needed(
|
||||||
inventory,
|
inventory,
|
||||||
|
|||||||
@@ -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
|
# 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
|
# 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
|
# Some modules work on the related fields of an endpoint. These modules will not have an auto-associated endpoint
|
||||||
no_endpoint_for_module = [
|
no_endpoint_for_module = [
|
||||||
|
|||||||
Reference in New Issue
Block a user