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
f16751de
Commit
f16751de
authored
Apr 22, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2746 from lwade/ec2region
Add region parameter and changed connection code.
parents
f9f1d5ee
8c801436
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
10 deletions
+26
-10
library/ec2
+26
-10
No files found.
library/ec2
View file @
f16751de
...
...
@@ -19,7 +19,7 @@ DOCUMENTATION = '''
module: ec2
short_description: create an instance in ec2, return instanceid
description:
- creates ec2 instances and optionally waits for it to be 'running'. This module has a dependency on python-boto
.
- creates ec2 instances and optionally waits for it to be 'running'. This module has a dependency on python-boto
>= 2.5
version_added: "0.9"
options:
key_name:
...
...
@@ -47,6 +47,13 @@ options:
required: false
default: null
aliases: []
region:
version_added: "1.2"
description:
- the EC2 region to use
required: false
default: null
aliases: []
zone:
version_added: "1.2"
description:
...
...
@@ -191,7 +198,7 @@ import sys
import
time
try
:
import
boto
import
boto
.ec2
except
ImportError
:
print
"failed=True msg='boto required for this module'"
sys
.
exit
(
1
)
...
...
@@ -203,6 +210,7 @@ def main():
id
=
dict
(),
group
=
dict
(),
group_id
=
dict
(),
region
=
dict
(
choices
=
[
'eu-west-1'
,
'sa-east-1'
,
'us-east-1'
,
'ap-northeast-1'
,
'us-west-2'
,
'us-west-1'
,
'ap-southeast-1'
,
'ap-southeast-2'
]),
zone
=
dict
(),
instance_type
=
dict
(
aliases
=
[
'type'
]),
image
=
dict
(
required
=
True
),
...
...
@@ -226,6 +234,7 @@ def main():
id
=
module
.
params
.
get
(
'id'
)
group_name
=
module
.
params
.
get
(
'group'
)
group_id
=
module
.
params
.
get
(
'group_id'
)
region
=
module
.
params
.
get
(
'region'
)
zone
=
module
.
params
.
get
(
'zone'
)
instance_type
=
module
.
params
.
get
(
'instance_type'
)
image
=
module
.
params
.
get
(
'image'
)
...
...
@@ -251,16 +260,23 @@ def main():
if
not
ec2_access_key
and
'EC2_ACCESS_KEY'
in
os
.
environ
:
ec2_access_key
=
os
.
environ
[
'EC2_ACCESS_KEY'
]
try
:
if
ec2_url
:
# if we have an URL set, connect to the specified endpoint
ec2
=
boto
.
connect_ec2_endpoint
(
ec2_url
,
ec2_access_key
,
ec2_secret_key
)
else
:
# otherwise it's Amazon.
ec2
=
boto
.
connect_ec2
(
ec2_access_key
,
ec2_secret_key
)
except
boto
.
exception
.
NoAuthHandlerFound
,
e
:
module
.
fail_json
(
msg
=
str
(
e
))
# If we have a region specified, connect to its endpoint.
if
region
:
try
:
ec2
=
boto
.
ec2
.
connect_to_region
(
region
,
aws_access_key_id
=
ec2_access_key
,
aws_secret_access_key
=
ec2_secret_key
)
except
boto
.
exception
.
NoAuthHandlerFound
,
e
:
module
.
fail_json
(
msg
=
str
(
e
))
# Otherwise, no region so we fallback to the old connection method
else
:
try
:
if
ec2_url
:
# if we have an URL set, connect to the specified endpoint
ec2
=
boto
.
connect_ec2_endpoint
(
ec2_url
,
ec2_access_key
,
ec2_secret_key
)
else
:
# otherwise it's Amazon.
ec2
=
boto
.
connect_ec2
(
ec2_access_key
,
ec2_secret_key
)
except
boto
.
exception
.
NoAuthHandlerFound
,
e
:
module
.
fail_json
(
msg
=
str
(
e
))
# Here we try to lookup the group name from the security group id - if group_id is set.
try
:
if
group_id
:
grp_details
=
ec2
.
get_all_security_groups
(
group_ids
=
group_id
)
...
...
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