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
8c801436
Commit
8c801436
authored
Apr 22, 2013
by
Lester Wade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add region parameter and changed connection code.
parent
66afe133
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
library/ec2
+19
-3
No files found.
library/ec2
View file @
8c801436
...
@@ -19,7 +19,7 @@ DOCUMENTATION = '''
...
@@ -19,7 +19,7 @@ DOCUMENTATION = '''
module: ec2
module: ec2
short_description: create an instance in ec2, return instanceid
short_description: create an instance in ec2, return instanceid
description:
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"
version_added: "0.9"
options:
options:
key_name:
key_name:
...
@@ -47,6 +47,13 @@ options:
...
@@ -47,6 +47,13 @@ options:
required: false
required: false
default: null
default: null
aliases: []
aliases: []
region:
version_added: "1.2"
description:
- the EC2 region to use
required: false
default: null
aliases: []
zone:
zone:
version_added: "1.2"
version_added: "1.2"
description:
description:
...
@@ -191,7 +198,7 @@ import sys
...
@@ -191,7 +198,7 @@ import sys
import
time
import
time
try
:
try
:
import
boto
import
boto
.ec2
except
ImportError
:
except
ImportError
:
print
"failed=True msg='boto required for this module'"
print
"failed=True msg='boto required for this module'"
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
@@ -203,6 +210,7 @@ def main():
...
@@ -203,6 +210,7 @@ def main():
id
=
dict
(),
id
=
dict
(),
group
=
dict
(),
group
=
dict
(),
group_id
=
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
(),
zone
=
dict
(),
instance_type
=
dict
(
aliases
=
[
'type'
]),
instance_type
=
dict
(
aliases
=
[
'type'
]),
image
=
dict
(
required
=
True
),
image
=
dict
(
required
=
True
),
...
@@ -226,6 +234,7 @@ def main():
...
@@ -226,6 +234,7 @@ def main():
id
=
module
.
params
.
get
(
'id'
)
id
=
module
.
params
.
get
(
'id'
)
group_name
=
module
.
params
.
get
(
'group'
)
group_name
=
module
.
params
.
get
(
'group'
)
group_id
=
module
.
params
.
get
(
'group_id'
)
group_id
=
module
.
params
.
get
(
'group_id'
)
region
=
module
.
params
.
get
(
'region'
)
zone
=
module
.
params
.
get
(
'zone'
)
zone
=
module
.
params
.
get
(
'zone'
)
instance_type
=
module
.
params
.
get
(
'instance_type'
)
instance_type
=
module
.
params
.
get
(
'instance_type'
)
image
=
module
.
params
.
get
(
'image'
)
image
=
module
.
params
.
get
(
'image'
)
...
@@ -251,6 +260,14 @@ def main():
...
@@ -251,6 +260,14 @@ def main():
if
not
ec2_access_key
and
'EC2_ACCESS_KEY'
in
os
.
environ
:
if
not
ec2_access_key
and
'EC2_ACCESS_KEY'
in
os
.
environ
:
ec2_access_key
=
os
.
environ
[
'EC2_ACCESS_KEY'
]
ec2_access_key
=
os
.
environ
[
'EC2_ACCESS_KEY'
]
# 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
:
try
:
if
ec2_url
:
# if we have an URL set, connect to the specified endpoint
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
)
ec2
=
boto
.
connect_ec2_endpoint
(
ec2_url
,
ec2_access_key
,
ec2_secret_key
)
...
@@ -260,7 +277,6 @@ def main():
...
@@ -260,7 +277,6 @@ def main():
module
.
fail_json
(
msg
=
str
(
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.
# Here we try to lookup the group name from the security group id - if group_id is set.
try
:
try
:
if
group_id
:
if
group_id
:
grp_details
=
ec2
.
get_all_security_groups
(
group_ids
=
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