From def76a3c3bb61c15f6a1160c6a90889e20c85744 Mon Sep 17 00:00:00 2001 From: Lee Shakespeare Date: Thu, 18 May 2017 23:44:33 +0100 Subject: [PATCH] Lookup credential id and pass in credential rather than scm_credential (#24624) * Lookup credential id and pass in credential rather than scm_credential * Change the excepting handling to catch missing credentials * Make error messages for not found lookups more useful --- .../ansible_tower/tower_project.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py index 30b25d1c08..6aeabe7187 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py @@ -208,21 +208,27 @@ def main(): project = tower_cli.get_resource('project') try: if state == 'present': - org_res = tower_cli.get_resource('organization') - org = org_res.get(name=organization) + try: + org_res = tower_cli.get_resource('organization') + org = org_res.get(name=organization) + except (exc.NotFound) as excinfo: + module.fail_json(msg='Failed to update project, organization not found: {0}'.format(organization), changed=False) + try: + cred_res = tower_cli.get_resource('credential') + cred = cred_res.get(name=scm_credential) + except (exc.NotFound) as excinfo: + module.fail_json(msg='Failed to update project, credential not found: {0}'.format(scm_credential), changed=False) result = project.modify(name=name, description=description, organization=org['id'], scm_type=scm_type, scm_url=scm_url, local_path=local_path, - scm_branch=scm_branch, scm_clean=scm_clean, scm_credential=scm_credential, + scm_branch=scm_branch, scm_clean=scm_clean, credential=cred['id'], scm_delete_on_update=scm_delete_on_update, scm_update_on_launch=scm_update_on_launch, create_on_missing=True) json_output['id'] = result['id'] elif state == 'absent': result = project.delete(name=name) - except (exc.NotFound) as excinfo: - module.fail_json(msg='Failed to update project, organization not found: {0}'.format(excinfo), changed=False) except (exc.ConnectionError, exc.BadRequest) as excinfo: module.fail_json(msg='Failed to update project: {0}'.format(excinfo), changed=False)