From 641f8b4ef6a706f8e45a317445b30eadf3e3f5ba Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Mon, 26 Feb 2018 13:12:54 -0500 Subject: [PATCH] tower cred: support credential kind/type for /api/v1/ and /api/v2/ (#36662) older versions of Tower (3.1) don't have a concept of CredentialTypes (this was introduced in Tower 3.2). This change detects older versions of pre-3.2 tower-cli that *only* support the deprecated `kind` attribute. --- .../ansible_tower/tower_credential.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py index 9555538df00..ded57cc19cd 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py @@ -258,8 +258,16 @@ def main(): org = org_res.get(name=organization) params['organization'] = org['id'] - credential_type = credential_type_for_v1_kind(module.params, module) - params['credential_type'] = credential_type['id'] + try: + tower_cli.get_resource('credential_type') + except (AttributeError): + # /api/v1/ backwards compat + # older versions of tower-cli don't *have* a credential_type + # resource + params['kind'] = module.params['kind'] + else: + credential_type = credential_type_for_v1_kind(module.params, module) + params['credential_type'] = credential_type['id'] if module.params.get('description'): params['description'] = module.params.get('description')