From fe3aa6ce2bd64d33faab41dd4636379416a51821 Mon Sep 17 00:00:00 2001 From: sean-m-sullivan Date: Thu, 16 Feb 2023 21:26:41 -0500 Subject: [PATCH] fix inventory prompt on launch for workflow nodes --- .../plugins/modules/workflow_job_template.py | 35 ++++++++++++++++--- .../workflow_job_template/tasks/main.yml | 5 +++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/awx_collection/plugins/modules/workflow_job_template.py b/awx_collection/plugins/modules/workflow_job_template.py index 41c5b66573..19954877b7 100644 --- a/awx_collection/plugins/modules/workflow_job_template.py +++ b/awx_collection/plugins/modules/workflow_job_template.py @@ -183,7 +183,21 @@ options: inventory: description: - Inventory applied as a prompt, if job template prompts for inventory - type: str + type: dict + suboptions: + name: + description: + - Name Inventory to be applied to job as launch-time prompts. + type: str + organization: + description: + - Name of key for use in model for organizational reference + type: dict + suboptions: + name: + description: + - The organization of the credentials exists in. + type: str scm_branch: description: - SCM branch applied as a prompt, if job template prompts for SCM branch @@ -544,6 +558,10 @@ EXAMPLES = ''' type: job_template execution_environment: name: My EE + inventory: + name: Test inventory + organization: + name: Default related: credentials: - name: cyberark @@ -613,10 +631,6 @@ def create_workflow_nodes(module, response, workflow_nodes, workflow_id): if workflow_node['unified_job_template']['type'] != 'workflow_approval': module.fail_json(msg="Unable to Find unified_job_template: {0}".format(search_fields)) - inventory = workflow_node.get('inventory') - if inventory: - workflow_node_fields['inventory'] = module.resolve_name_to_id('inventories', inventory) - # Lookup Values for other fields for field_name in ( @@ -645,6 +659,17 @@ def create_workflow_nodes(module, response, workflow_nodes, workflow_id): 'execution_environments', name_or_id=workflow_node['execution_environment']['name'] )['id'] + # Two lookup methods are used based on a fix added in 21.11.0, and the awx export model + if 'inventory' in workflow_node: + if 'name' in workflow_node['inventory']: + inv_lookup_data = {} + if 'organization' in workflow_node['inventory']: + inv_lookup_data['organization'] = module.resolve_name_to_id('organizations', workflow_node['inventory']['organization']['name']) + workflow_node_fields['inventory'] = module.get_one( + 'inventories', name_or_id=workflow_node['inventory']['name'], data=inv_lookup_data)['id'] + else: + workflow_node_fields['inventory'] = module.get_one('inventories', name_or_id=workflow_node['inventory'])['id'] + # Set Search fields search_fields['workflow_job_template'] = workflow_node_fields['workflow_job_template'] = workflow_id diff --git a/awx_collection/tests/integration/targets/workflow_job_template/tasks/main.yml b/awx_collection/tests/integration/targets/workflow_job_template/tasks/main.yml index 1477193e6c..e5f3366cd3 100644 --- a/awx_collection/tests/integration/targets/workflow_job_template/tasks/main.yml +++ b/awx_collection/tests/integration/targets/workflow_job_template/tasks/main.yml @@ -493,6 +493,7 @@ workflow_job_template: name: "copy_{{ wfjt_name }}" organization: Default + ask_inventory_on_launch: true survey_spec: name: Basic Survey description: Basic Survey @@ -737,6 +738,10 @@ timeout: 23 execution_environment: name: "{{ ee1 }}" + inventory: + name: Test inventory + organization: + name: Default related: credentials: - name: "{{ scm_cred_name }}"