From 0f10c4e8d2b3d28163084282ada28496538a72cb Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 3 Jun 2019 20:53:54 +0530 Subject: [PATCH] aws: Handle exceptions while describing metric alarm (#57304) Handle exceptions raised while describing the metric alarms rather than printing tracebacks. Fixes: #55786 Signed-off-by: Abhijeet Kasurde --- .../modules/cloud/amazon/ec2_metric_alarm.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_metric_alarm.py b/lib/ansible/modules/cloud/amazon/ec2_metric_alarm.py index 8bef5186a14..1f271cd2c0d 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_metric_alarm.py +++ b/lib/ansible/modules/cloud/amazon/ec2_metric_alarm.py @@ -162,6 +162,7 @@ try: except ImportError: pass # Taken care of by ec2.HAS_BOTO +import traceback from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.ec2 import (AnsibleAWSError, HAS_BOTO, connect_to_aws, ec2_argument_spec, get_aws_connection_info) @@ -184,7 +185,11 @@ def create_metric_alarm(connection, module): insufficient_data_actions = module.params.get('insufficient_data_actions') ok_actions = module.params.get('ok_actions') - alarms = connection.describe_alarms(alarm_names=[name]) + alarms = None + try: + alarms = connection.describe_alarms(alarm_names=[name]) + except BotoServerError as e: + module.fail_json(msg="Failed to describe alarm %s: %s" % (name, str(e)), exception=traceback.format_exc()) if not alarms: @@ -209,7 +214,7 @@ def create_metric_alarm(connection, module): changed = True alarms = connection.describe_alarms(alarm_names=[name]) except BotoServerError as e: - module.fail_json(msg=str(e)) + module.fail_json(msg="Failed to create alarm %s: %s" % (name, str(e)), exception=traceback.format_exc()) else: alarm = alarms[0] @@ -272,7 +277,11 @@ def create_metric_alarm(connection, module): def delete_metric_alarm(connection, module): name = module.params.get('name') - alarms = connection.describe_alarms(alarm_names=[name]) + alarms = None + try: + alarms = connection.describe_alarms(alarm_names=[name]) + except BotoServerError as e: + module.fail_json(msg="Failed to describe alarm %s: %s" % (name, str(e)), exception=traceback.format_exc()) if alarms: try: