Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
3bf1edfd
Commit
3bf1edfd
authored
Jul 23, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11591 from defionscode/boto3
Connection function for boto3
parents
7bc789ba
6ea77293
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
12 deletions
+37
-12
lib/ansible/module_utils/ec2.py
+37
-12
No files found.
lib/ansible/module_utils/ec2.py
View file @
3bf1edfd
...
...
@@ -33,6 +33,19 @@ except:
HAS_LOOSE_VERSION
=
False
def
boto3_conn
(
module
,
conn_type
=
None
,
resource
=
None
,
region
=
None
,
endpoint
=
None
,
**
params
):
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'
)
resource
=
boto3
.
session
.
Session
()
.
resource
(
resource
,
region_name
=
region
,
endpoint_url
=
endpoint
,
**
params
)
client
=
resource
.
meta
.
client
if
conn_type
==
'resource'
:
return
resource
elif
conn_type
==
'client'
:
return
client
else
:
return
client
,
resource
def
aws_common_argument_spec
():
return
dict
(
...
...
@@ -59,7 +72,7 @@ def boto_supports_profile_name():
return
hasattr
(
boto
.
ec2
.
EC2Connection
,
'profile_name'
)
def
get_aws_connection_info
(
module
):
def
get_aws_connection_info
(
module
,
boto3
=
False
):
# Check module args for credentials, then check environment vars
# access_key
...
...
@@ -120,19 +133,31 @@ def get_aws_connection_info(module):
# in case security_token came in as empty string
security_token
=
None
boto_params
=
dict
(
aws_access_key_id
=
access_key
,
aws_secret_access_key
=
secret_key
,
security_token
=
security_token
)
if
boto3
:
boto_params
=
dict
(
aws_access_key_id
=
access_key
,
aws_secret_access_key
=
secret_key
,
aws_session_token
=
security_token
)
if
validate_certs
:
boto_params
[
'verify'
]
=
validate_certs
# profile_name only works as a key in boto >= 2.24
# so only set profile_name if passed as an argument
if
profile_name
:
if
not
boto_supports_profile_name
():
module
.
fail_json
(
"boto does not support profile_name before 2.24"
)
boto_params
[
'profile_name'
]
=
profile_name
if
profile_name
:
boto_params
[
'profile_name'
]
=
profile_name
if
validate_certs
and
HAS_LOOSE_VERSION
and
LooseVersion
(
boto
.
Version
)
>=
LooseVersion
(
"2.6.0"
):
boto_params
[
'validate_certs'
]
=
validate_certs
else
:
boto_params
=
dict
(
aws_access_key_id
=
access_key
,
aws_secret_access_key
=
secret_key
,
security_token
=
security_token
)
# profile_name only works as a key in boto >= 2.24
# so only set profile_name if passed as an argument
if
profile_name
:
if
not
boto_supports_profile_name
():
module
.
fail_json
(
"boto does not support profile_name before 2.24"
)
boto_params
[
'profile_name'
]
=
profile_name
if
validate_certs
and
HAS_LOOSE_VERSION
and
LooseVersion
(
boto
.
Version
)
>=
LooseVersion
(
"2.6.0"
):
boto_params
[
'validate_certs'
]
=
validate_certs
return
region
,
ec2_url
,
boto_params
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment