From df0bd0797ca98bc647a36d58d4451905910e76e3 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Tue, 9 Apr 2019 22:08:11 +0900 Subject: [PATCH] Fix handling of inventory and credential options for tower_job_launch (#54967) - Fixed issue #25017,#37567 - Add example for prompt on launch - Add integration test for prompt on launch Signed-off-by: Hideki Saito --- .../ansible_tower/tower_job_launch.py | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py index d05abba097..87e9b2be22 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py @@ -58,11 +58,24 @@ extends_documentation_fragment: tower ''' EXAMPLES = ''' +# Launch a job template - name: Launch a job tower_job_launch: job_template: "My Job Template" register: job +- name: Wait for job max 120s + tower_job_wait: + job_id: job.id + timeout: 120 + +# Launch job template with inventory and credential for prompt on launch +- name: Launch a job with inventory and credential + tower_job_launch: + job_template: "My Job Template" + inventory: "My Inventory" + credential: "My Credential" + register: job - name: Wait for job max 120s tower_job_wait: job_id: job.id @@ -96,10 +109,10 @@ except ImportError: def main(): argument_spec = dict( - job_template=dict(required=True), + job_template=dict(required=True, type='str'), job_type=dict(choices=['run', 'check', 'scan']), - inventory=dict(), - credential=dict(), + inventory=dict(type='str', default=None), + credential=dict(type='str', default=None), limit=dict(), tags=dict(type='list'), extra_vars=dict(type='list'), @@ -126,8 +139,9 @@ def main(): for field in lookup_fields: try: name = params.pop(field) - result = tower_cli.get_resource(field).get(name=name) - params[field] = result['id'] + if name: + result = tower_cli.get_resource(field).get(name=name) + params[field] = result['id'] except exc.NotFound as excinfo: module.fail_json(msg='Unable to launch job, {0}/{1} was not found: {2}'.format(field, name, excinfo), changed=False)