From 5b0eae75fa1ab10ec556b163291e00f4b60cde65 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 6 Mar 2019 16:48:43 +0530 Subject: [PATCH] tower: Handle AuthError (#53377) Handle AuthError raised when user provides incorrect password for Tower admin user. Fixes: #50535 Signed-off-by: Abhijeet Kasurde --- .../web_infrastructure/ansible_tower/tower_credential.py | 2 +- .../web_infrastructure/ansible_tower/tower_credential_type.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_group.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_host.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_inventory.py | 2 +- .../web_infrastructure/ansible_tower/tower_inventory_source.py | 2 +- .../web_infrastructure/ansible_tower/tower_job_cancel.py | 2 +- .../web_infrastructure/ansible_tower/tower_job_launch.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_job_list.py | 2 +- .../web_infrastructure/ansible_tower/tower_job_template.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_job_wait.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_label.py | 2 +- .../web_infrastructure/ansible_tower/tower_notification.py | 2 +- .../web_infrastructure/ansible_tower/tower_organization.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_project.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_receive.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_role.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_send.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_settings.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_team.py | 2 +- .../modules/web_infrastructure/ansible_tower/tower_user.py | 2 +- .../web_infrastructure/ansible_tower/tower_workflow_launch.py | 2 +- .../web_infrastructure/ansible_tower/tower_workflow_template.py | 2 +- 23 files changed, 23 insertions(+), 23 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 46152baebf7..6fe95e59cb9 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py @@ -307,7 +307,7 @@ def main(): result = credential.delete(**params) except (exc.NotFound) as excinfo: module.fail_json(msg='Failed to update credential, organization not found: {0}'.format(excinfo), changed=False) - except (exc.ConnectionError, exc.BadRequest, exc.NotFound) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.NotFound, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update credential: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential_type.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential_type.py index e8f28d98678..12b75a4029e 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential_type.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential_type.py @@ -159,7 +159,7 @@ def main(): params['fail_on_missing'] = False result = credential_type_res.delete(**params) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json( msg='Failed to update credential type: {0}'.format(excinfo), changed=False diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py index 50772891ff5..666b7386b87 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py @@ -166,7 +166,7 @@ def main(): result = group.delete(**params) except (exc.NotFound) as excinfo: module.fail_json(msg='Failed to update the group, inventory not found: {0}'.format(excinfo), changed=False) - except (exc.ConnectionError, exc.BadRequest, exc.NotFound) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.NotFound, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update the group: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py index 492c4842c06..6fd411a636f 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py @@ -120,7 +120,7 @@ def main(): result = host.delete(name=name, inventory=inv['id']) except (exc.NotFound) as excinfo: module.fail_json(msg='Failed to update host, inventory not found: {0}'.format(excinfo), changed=False) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update host: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py index 1be24773211..c709ab7c8ad 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py @@ -119,7 +119,7 @@ def main(): result = inventory.delete(name=name, organization=org['id']) except (exc.NotFound) as excinfo: module.fail_json(msg='Failed to update inventory, organization not found: {0}'.format(excinfo), changed=False) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update inventory: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory_source.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory_source.py index 11c6439a1d7..48a1e9ce1d0 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory_source.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory_source.py @@ -302,7 +302,7 @@ def main(): params['fail_on_missing'] = False result = inventory_source.delete(**params) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update inventory source: \ {0}'.format(excinfo), changed=False) diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py index f2f5f8eadae..02fa3b7b19b 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py @@ -89,7 +89,7 @@ def main(): try: result = job.cancel(job_id, **params) json_output['id'] = job_id - except (exc.ConnectionError, exc.BadRequest, exc.TowerCLIError) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.TowerCLIError, exc.AuthError) as excinfo: module.fail_json(msg='Unable to cancel job_id/{0}: {1}'.format(job_id, excinfo), changed=False) json_output['changed'] = result['changed'] 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 c34ec3dd23e..d05abba0975 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 @@ -134,7 +134,7 @@ def main(): result = job.launch(no_input=True, **params) json_output['id'] = result['id'] json_output['status'] = result['status'] - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Unable to launch job: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py index 51eda5ecdb4..5665f8d935c 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py @@ -118,7 +118,7 @@ def main(): if query: params['query'] = query.items() json_output = job.list(**params) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Failed to list jobs: {0}'.format(excinfo), changed=False) module.exit_json(**json_output) diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py index 36106998a33..8e18195cb84 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py @@ -326,7 +326,7 @@ def main(): json_output['id'] = result['id'] elif state == 'absent': result = jt.delete(**params) - except (exc.ConnectionError, exc.BadRequest, exc.NotFound) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.NotFound, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update job template: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py index 89742891579..42bbbb68eee 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py @@ -132,7 +132,7 @@ def main(): json_output['timeout'] = True except exc.NotFound as excinfo: fail_json = dict(msg='Unable to wait, no job_id {0} found: {1}'.format(job_id, excinfo), changed=False) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: fail_json = dict(msg='Unable to wait for job: {0}'.format(excinfo), changed=False) if fail_json is not None: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py index 554d154cb1a..eca8ea1b554 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py @@ -91,7 +91,7 @@ def main(): result = label.delete(name=name, organization=org['id']) except (exc.NotFound) as excinfo: module.fail_json(msg='Failed to update label, organization not found: {0}'.format(excinfo), changed=False) - except (exc.ConnectionError, exc.BadRequest, exc.NotFound) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.NotFound, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update label: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_notification.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_notification.py index 4b6d74a233c..ae3ab87f7ec 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_notification.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_notification.py @@ -382,7 +382,7 @@ def main(): result = notification_template.delete(name=name) except (exc.NotFound) as excinfo: module.fail_json(msg='Failed to update notification template, organization not found: {0}'.format(excinfo), changed=False) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update notification template: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py index 8acbfd5108d..bba58d88944 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py @@ -84,7 +84,7 @@ def main(): json_output['id'] = result['id'] elif state == 'absent': result = organization.delete(name=name) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update the organization: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] 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 38adfd4a36c..f8c380ce797 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py @@ -202,7 +202,7 @@ def main(): json_output['id'] = result['id'] elif state == 'absent': result = project.delete(name=name) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update project: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_receive.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_receive.py index 1bbb0067373..57fdd16df43 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_receive.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_receive.py @@ -164,7 +164,7 @@ def main(): result['assets'] = receiver.export_assets(all=export_all, asset_input=assets_to_export) module.exit_json(**result) except TowerCLIError as e: - result['message'] = e + result['message'] = e.message module.fail_json(msg='Receive Failed', **result) diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py index 38a56514b96..cc3ce155777 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py @@ -144,7 +144,7 @@ def main(): json_output['id'] = result['id'] elif state == 'absent': result = role.revoke(**params) - except (exc.ConnectionError, exc.BadRequest, exc.NotFound) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.NotFound, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update role: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_send.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_send.py index 387e82bcb79..4010ee7a1b5 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_send.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_send.py @@ -148,7 +148,7 @@ def main(): if sender.changed_messages > 0: result['changed'] = True except TowerCLIError as e: - result['msg'] = e + result['msg'] = e.message failed = True finally: if path is not None: diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_settings.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_settings.py index 1a2acbfb9e0..6695fdf302f 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_settings.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_settings.py @@ -91,7 +91,7 @@ def main(): json_output['id'] = result['id'] json_output['value'] = result['value'] - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Failed to modify the setting: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py index 4c49fd54477..5174d39ba76 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py @@ -96,7 +96,7 @@ def main(): result = team.delete(name=name, organization=org['id']) except (exc.NotFound) as excinfo: module.fail_json(msg='Failed to update team, organization not found: {0}'.format(excinfo), changed=False) - except (exc.ConnectionError, exc.BadRequest, exc.NotFound) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.NotFound, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update team: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py index 86baf18e90e..a16a44d823c 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py @@ -119,7 +119,7 @@ def main(): json_output['id'] = result['id'] elif state == 'absent': result = user.delete(username=username) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update the user: {0}'.format(excinfo), changed=False) json_output['changed'] = result['changed'] diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_workflow_launch.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_workflow_launch.py index a7174ec3b2c..e55e800482c 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_workflow_launch.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_workflow_launch.py @@ -51,7 +51,7 @@ tower_version: type: str sample: '3.4.0' job_info: - description: dictionnary containing information about the workflow executed + description: dictionary containing information about the workflow executed returned: If workflow launched type: dict ''' diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_workflow_template.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_workflow_template.py index 89e07444114..ef8565c05e2 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_workflow_template.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_workflow_template.py @@ -168,7 +168,7 @@ def main(): elif state == 'absent': params['fail_on_missing'] = False result = wfjt_res.delete(**params) - except (exc.ConnectionError, exc.BadRequest) as excinfo: + except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo: module.fail_json(msg='Failed to update workflow template: \ {0}'.format(excinfo), changed=False)