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
6e0cb14b
Commit
6e0cb14b
authored
Jan 25, 2013
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1911 from tgerla/devel
Port ec2 module to Boto
parents
a5e6c18f
cafb717b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
35 deletions
+33
-35
library/ec2
+33
-35
No files found.
library/ec2
View file @
6e0cb14b
...
...
@@ -22,12 +22,12 @@ description:
- creates ec2 instances and optionally waits for it to be 'running'. This module has a dependency on the external I(euca2ools) package.
version_added: "0.9"
options:
key
pair
:
key
_name
:
description:
- key pair to use on the instance
required: true
default: null
aliases: []
aliases: [
'keypair'
]
group:
description:
- security group to use on the instance
...
...
@@ -92,25 +92,23 @@ options:
examples:
- code: "local_action: ec2 keypair=admin instance_type=m1.large image=emi-40603AD1 wait=true group=webserver"
description: "Examples from Ansible Playbooks"
requirements: [ "
euca2ools
" ]
author: Seth Vidal
requirements: [ "
boto
" ]
author: Seth Vidal
, Tim Gerla
'''
import
euca2ools.commands.euca.runinstance
s
import
sy
s
import
time
def
_run
(
cmd
):
# returns (rc, stdout, stderr) from shell command
process
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
True
)
stdout
,
stderr
=
process
.
communicate
()
return
(
process
.
returncode
,
stdout
,
stderr
)
try
:
import
boto
except
ImportError
:
print
"failed=True msg='boto required for this module'"
sys
.
exit
(
1
)
def
main
():
module
=
AnsibleModule
(
argument_spec
=
dict
(
key
pair
=
dict
(
required
=
True
),
key
_name
=
dict
(
required
=
True
,
aliases
=
[
'keypair'
]
),
group
=
dict
(
default
=
'default'
),
instance_type
=
dict
(
aliases
=
[
'type'
]),
image
=
dict
(
required
=
True
),
...
...
@@ -125,7 +123,7 @@ def main():
)
)
key
pair
=
module
.
params
.
get
(
'keypair
'
)
key
_name
=
module
.
params
.
get
(
'key_name
'
)
group
=
module
.
params
.
get
(
'group'
)
instance_type
=
module
.
params
.
get
(
'instance_type'
)
image
=
module
.
params
.
get
(
'image'
)
...
...
@@ -138,29 +136,29 @@ def main():
ec2_access_key
=
module
.
params
.
get
(
'ec2_access_key'
)
user_data
=
module
.
params
.
get
(
'user_data'
)
if
ec2_url
:
os
.
environ
[
'EC2_URL'
]
=
ec2_url
if
ec2_secret_key
:
os
.
environ
[
'EC2_SECRET_KEY'
]
=
ec2_secret_key
if
ec2_access_key
:
os
.
environ
[
'EC2_ACCESS_KEY'
]
=
ec2_access_key
# allow eucarc environment variables to be used if ansible vars aren't set
if
not
ec2_url
and
'EC2_URL'
in
os
.
environ
:
ec2_url
=
os
.
environ
[
'EC2_URL'
]
if
not
ec2_secret_key
and
'EC2_SECRET_KEY'
in
os
.
environ
:
ec2_secret_key
=
os
.
environ
[
'EC2_SECRET_KEY'
]
if
not
ec2_access_key
and
'EC2_ACCESS_KEY'
in
os
.
environ
:
ec2_access_key
=
os
.
environ
[
'EC2_ACCESS_KEY'
]
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
)
# yes I recognize how hacky this is - but it is easier than rewriting
# all the try/except's myself.
sys
.
argv
.
append
(
image
)
eri
=
euca2ools
.
commands
.
euca
.
runinstances
.
RunInstances
()
conn
=
eri
.
make_connection
()
res
=
eri
.
make_request_cli
(
conn
,
'run_instances'
,
image_id
=
image
,
min_count
=
1
,
max_count
=
1
,
key_name
=
keypair
,
security_groups
=
[
group
],
instance_type
=
instance_type
,
kernel_id
=
kernel
,
ramdisk_id
=
ramdisk
,
user_data
=
user_data
)
try
:
res
=
ec2
.
run_instances
(
image
,
key_name
=
key_name
,
min_count
=
1
,
max_count
=
1
,
security_groups
=
[
group
],
instance_type
=
instance_type
,
kernel_id
=
kernel
,
ramdisk_id
=
ramdisk
,
user_data
=
user_data
)
except
boto
.
exception
.
EC2ResponseError
as
e
:
module
.
fail_json
(
msg
=
"
%
s:
%
s"
%
(
e
.
error_code
,
e
.
error_message
))
instids
=
[
i
.
id
for
i
in
res
.
instances
]
...
...
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