Mdd utils ec2 no profile fix (#26528)
* Handle boto.provider.ProfileNotFoundError when doing connect_to_aws
This commit is contained in:
parent
64f0eb50ff
commit
43989d35b7
1 changed files with 6 additions and 3 deletions
|
@ -278,7 +278,10 @@ def boto_fix_security_token_in_profile(conn, profile_name):
|
||||||
|
|
||||||
|
|
||||||
def connect_to_aws(aws_module, region, **params):
|
def connect_to_aws(aws_module, region, **params):
|
||||||
conn = aws_module.connect_to_region(region, **params)
|
try:
|
||||||
|
conn = aws_module.connect_to_region(region, **params)
|
||||||
|
except(boto.provider.ProfileNotFoundError):
|
||||||
|
raise AnsibleAWSError("Profile given for AWS was not found. Please fix and retry.")
|
||||||
if not conn:
|
if not conn:
|
||||||
if region not in [aws_module_region.name for aws_module_region in aws_module.regions()]:
|
if region not in [aws_module_region.name for aws_module_region in aws_module.regions()]:
|
||||||
raise AnsibleAWSError("Region %s does not seem to be available for aws module %s. If the region definitely exists, you may need to upgrade "
|
raise AnsibleAWSError("Region %s does not seem to be available for aws module %s. If the region definitely exists, you may need to upgrade "
|
||||||
|
@ -300,13 +303,13 @@ def ec2_connect(module):
|
||||||
if region:
|
if region:
|
||||||
try:
|
try:
|
||||||
ec2 = connect_to_aws(boto.ec2, region, **boto_params)
|
ec2 = connect_to_aws(boto.ec2, region, **boto_params)
|
||||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError, boto.provider.ProfileNotFoundError) as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
# Otherwise, no region so we fallback to the old connection method
|
# Otherwise, no region so we fallback to the old connection method
|
||||||
elif ec2_url:
|
elif ec2_url:
|
||||||
try:
|
try:
|
||||||
ec2 = boto.connect_ec2_endpoint(ec2_url, **boto_params)
|
ec2 = boto.connect_ec2_endpoint(ec2_url, **boto_params)
|
||||||
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e:
|
except (boto.exception.NoAuthHandlerFound, AnsibleAWSError, boto.provider.ProfileNotFoundError) as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Either region or ec2_url must be specified")
|
module.fail_json(msg="Either region or ec2_url must be specified")
|
||||||
|
|
Loading…
Reference in a new issue