From c40ca718d00b4ec7937531c79582f7f81505ed10 Mon Sep 17 00:00:00 2001 From: sean-m-sullivan Date: Thu, 28 Jan 2021 08:31:52 -0600 Subject: [PATCH 1/4] add org to job launch --- awx_collection/plugins/modules/tower_job_launch.py | 13 ++++++++++++- awx_collection/test/awx/test_job_template.py | 1 + .../targets/tower_job_launch/tasks/main.yml | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/awx_collection/plugins/modules/tower_job_launch.py b/awx_collection/plugins/modules/tower_job_launch.py index 9b118afcec..2f9ddd3e31 100644 --- a/awx_collection/plugins/modules/tower_job_launch.py +++ b/awx_collection/plugins/modules/tower_job_launch.py @@ -37,6 +37,12 @@ options: description: - Inventory to use for the job, only used if prompt for inventory is set. type: str + organization: + description: + - Organization the workflow job template exists in. + - Used to help lookup the object, cannot be modified using this module. + - If not provided, will lookup by name only, which does not work with duplicates. + type: str credentials: description: - Credential to use for job, only used if prompt for credential is set. @@ -149,6 +155,7 @@ def main(): name=dict(required=True, aliases=['job_template']), job_type=dict(choices=['run', 'check']), inventory=dict(default=None), + organization=dict(), # Credentials will be a str instead of a list for backwards compatability credentials=dict(type='list', default=None, aliases=['credential'], elements='str'), limit=dict(), @@ -172,6 +179,7 @@ def main(): name = module.params.get('name') optional_args['job_type'] = module.params.get('job_type') inventory = module.params.get('inventory') + organization = module.params.get('organization') credentials = module.params.get('credentials') optional_args['limit'] = module.params.get('limit') optional_args['tags'] = module.params.get('tags') @@ -201,7 +209,10 @@ def main(): post_data['credentials'].append(module.resolve_name_to_id('credentials', credential)) # Attempt to look up job_template based on the provided name - job_template = module.get_one('job_templates', name_or_id=name) + lookup_data = {} + if organization: + lookup_data['organization'] = module.resolve_name_to_id('organizations', organization) + job_template = module.get_one('job_templates', name_or_id=name, data=lookup_data) if job_template is None: module.fail_json(msg="Unable to find job template by name {0}".format(name)) diff --git a/awx_collection/test/awx/test_job_template.py b/awx_collection/test/awx/test_job_template.py index 5d4100dac1..5a8f302e90 100644 --- a/awx_collection/test/awx/test_job_template.py +++ b/awx_collection/test/awx/test_job_template.py @@ -85,6 +85,7 @@ def test_job_launch_with_prompting(run_module, admin_user, project, inventory, m JobTemplate.objects.create( name='foo', project=project, + organization='Default' playbook='helloworld.yml', ask_variables_on_launch=True, ask_inventory_on_launch=True, diff --git a/awx_collection/tests/integration/targets/tower_job_launch/tasks/main.yml b/awx_collection/tests/integration/targets/tower_job_launch/tasks/main.yml index c74f6a8bd5..bc0321069a 100644 --- a/awx_collection/tests/integration/targets/tower_job_launch/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_job_launch/tasks/main.yml @@ -85,6 +85,7 @@ - name: Launch job template with inventory and credential for prompt on launch tower_job_launch: job_template: "{{ jt_name2 }}" + organization: Default register: result - assert: From aa5219cf30377f059b5058f6909a2e8d85ff8524 Mon Sep 17 00:00:00 2001 From: sean-m-sullivan Date: Thu, 28 Jan 2021 08:36:13 -0600 Subject: [PATCH 2/4] fix verbage --- awx_collection/plugins/modules/tower_job_launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx_collection/plugins/modules/tower_job_launch.py b/awx_collection/plugins/modules/tower_job_launch.py index 2f9ddd3e31..658d1cd06b 100644 --- a/awx_collection/plugins/modules/tower_job_launch.py +++ b/awx_collection/plugins/modules/tower_job_launch.py @@ -39,7 +39,7 @@ options: type: str organization: description: - - Organization the workflow job template exists in. + - Organization the job template exists in. - Used to help lookup the object, cannot be modified using this module. - If not provided, will lookup by name only, which does not work with duplicates. type: str From cc0d658b1c9c1b1db53a106fc8f6c94d02c736b4 Mon Sep 17 00:00:00 2001 From: sean-m-sullivan Date: Thu, 28 Jan 2021 10:16:27 -0600 Subject: [PATCH 3/4] fix typo --- awx_collection/test/awx/test_job_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx_collection/test/awx/test_job_template.py b/awx_collection/test/awx/test_job_template.py index 5a8f302e90..91f91a3c53 100644 --- a/awx_collection/test/awx/test_job_template.py +++ b/awx_collection/test/awx/test_job_template.py @@ -85,7 +85,7 @@ def test_job_launch_with_prompting(run_module, admin_user, project, inventory, m JobTemplate.objects.create( name='foo', project=project, - organization='Default' + organization='Default', playbook='helloworld.yml', ask_variables_on_launch=True, ask_inventory_on_launch=True, From e433e3ebc220935a31a04e73d94b0c593ebcb2df Mon Sep 17 00:00:00 2001 From: sean-m-sullivan Date: Thu, 28 Jan 2021 15:19:28 -0600 Subject: [PATCH 4/4] update logic --- awx_collection/test/awx/test_job_template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/awx_collection/test/awx/test_job_template.py b/awx_collection/test/awx/test_job_template.py index 91f91a3c53..8ec3d67bfc 100644 --- a/awx_collection/test/awx/test_job_template.py +++ b/awx_collection/test/awx/test_job_template.py @@ -81,11 +81,11 @@ def test_resets_job_template_values(run_module, admin_user, project, inventory): @pytest.mark.django_db -def test_job_launch_with_prompting(run_module, admin_user, project, inventory, machine_credential): +def test_job_launch_with_prompting(run_module, admin_user, project, organization, inventory, machine_credential): JobTemplate.objects.create( name='foo', project=project, - organization='Default', + organization=organization, playbook='helloworld.yml', ask_variables_on_launch=True, ask_inventory_on_launch=True,