Skip to content

Commit

Permalink
Merge pull request ansible#13053 from Etherdaemon/fix_13010_boto3_aws…
Browse files Browse the repository at this point in the history
…_profile

Fixes ansible#13010 by updating boto3 methods
  • Loading branch information
bcoca committed Nov 16, 2015
2 parents 89646d4 + 2739813 commit db27541
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/ansible/module_utils/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,25 @@


def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None, **params):
profile = params.pop('profile_name', None)
params['aws_session_token'] = params.pop('security_token', None)
params['verify'] = params.pop('validate_certs', None)

if conn_type not in ['both', 'resource', 'client']:
module.fail_json(msg='There is an issue in the code of the module. You must specify either both, resource or client to the conn_type parameter in the boto3_conn function call')

if conn_type == 'resource':
resource = boto3.session.Session().resource(resource, region_name=region, endpoint_url=endpoint, **params)
resource = boto3.session.Session(profile_name=profile).resource(resource, region_name=region, endpoint_url=endpoint, **params)
return resource
elif conn_type == 'client':
client = boto3.session.Session().client(resource, region_name=region, endpoint_url=endpoint, **params)
client = boto3.session.Session(profile_name=profile).client(resource, region_name=region, endpoint_url=endpoint, **params)
return client
else:
resource = boto3.session.Session().resource(resource, region_name=region, endpoint_url=endpoint, **params)
client = boto3.session.Session().client(resource, region_name=region, endpoint_url=endpoint, **params)
resource = boto3.session.Session(profile_name=profile).resource(resource, region_name=region, endpoint_url=endpoint, **params)
client = boto3.session.Session(profile_name=profile).client(resource, region_name=region, endpoint_url=endpoint, **params)
return client, resource


def aws_common_argument_spec():
return dict(
ec2_url=dict(),
Expand Down Expand Up @@ -153,7 +158,6 @@ def get_aws_connection_info(module, boto3=False):
if profile_name:
boto_params['profile_name'] = profile_name


else:
boto_params = dict(aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
Expand Down

0 comments on commit db27541

Please sign in to comment.