mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Return correct error message to user
botocore.exceptions.ClientError does not have message, which fails fail_json. Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
139e3477a7
commit
1e4ab5a038
1 changed files with 3 additions and 2 deletions
|
@ -168,6 +168,7 @@ from ansible.module_utils.ec2 import (
|
||||||
camel_dict_to_snake_dict,
|
camel_dict_to_snake_dict,
|
||||||
ansible_dict_to_boto3_filter_list
|
ansible_dict_to_boto3_filter_list
|
||||||
)
|
)
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import botocore
|
import botocore
|
||||||
|
@ -209,7 +210,7 @@ def describe_subnets(connection, module):
|
||||||
try:
|
try:
|
||||||
response = describe_subnets_with_backoff(connection, subnet_ids, filters)
|
response = describe_subnets_with_backoff(connection, subnet_ids, filters)
|
||||||
except botocore.exceptions.ClientError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg=e.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
module.fail_json(msg=to_native(e), exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
|
|
||||||
for subnet in response['Subnets']:
|
for subnet in response['Subnets']:
|
||||||
# for backwards compatibility
|
# for backwards compatibility
|
||||||
|
@ -240,7 +241,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params)
|
connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params)
|
||||||
except (botocore.exceptions.NoCredentialsError, botocore.exceptions.ProfileNotFound) as e:
|
except (botocore.exceptions.NoCredentialsError, botocore.exceptions.ProfileNotFound) as e:
|
||||||
module.fail_json(msg=e.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
module.fail_json(msg=to_native(e), exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Region must be specified")
|
module.fail_json(msg="Region must be specified")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue