Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
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
edx
configuration
Commits
6fba64ba
Commit
6fba64ba
authored
Jun 21, 2013
by
John Jarvis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changing the way the terminate options is used
parent
18a93a26
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
26 deletions
+35
-26
playbooks/edx_sandbox.yml
+0
-9
playbooks/edx_sandbox_jenkins.yml
+2
-1
playbooks/library/ec2
+33
-16
No files found.
playbooks/edx_sandbox.yml
View file @
6fba64ba
...
...
@@ -26,12 +26,3 @@
-
nginx
-
edxlocal
-
edxapp
-
name
:
Terminate instances
hosts
:
localhost
connection
:
local
tasks
:
-
name
:
Terminate instances that were previously launched
local_action
:
module
:
ec2
termination_list
:
${ec2.instances}
playbooks/edx_sandbox_jenkins.yml
View file @
6fba64ba
...
...
@@ -34,4 +34,5 @@
-
name
:
Terminate instances that were previously launched
local_action
:
module
:
ec2
termination_list
:
${ec2.instances}
state
:
'
absent'
instance_ids
:
${ec2.instance_ids}
playbooks/library/ec2
View file @
6fba64ba
...
...
@@ -163,13 +163,21 @@ options:
required: false
defualt: null
aliases: []
termination_list
:
instance_ids
:
version_added: "1.3"
description:
- list of instance
s to terminate in the form of [{id: <inst-id>}, {id: <inst-id>}].
- list of instance
ids, currently only used when state='absent'
required: false
default: null
aliases: []
state:
version_added: "1.3"
description:
- create or terminate instances
required: false
default: 'present'
aliases: []
requirements: [ "boto" ]
author: Seth Vidal, Tim Gerla, Lester Wade
...
...
@@ -260,7 +268,8 @@ local_action:
- name: Terminate instances that were previously launched
local_action:
module: ec2
termination_list: ${ec2.instances}
state: 'absent'
instance_ids: {{ec2.intance_ids}}
'''
...
...
@@ -439,14 +448,16 @@ def create_instances(module, ec2):
running_instances
.
append
(
inst
)
instance_dict_array
=
[]
created_instance_ids
=
[]
for
inst
in
running_instances
:
d
=
get_instance_info
(
inst
)
created_instance_ids
.
append
(
inst
.
id
)
instance_dict_array
.
append
(
d
)
return
instance_dict_array
return
(
instance_dict_array
,
created_instance_ids
)
def
terminate_instances
(
module
,
ec2
,
termination_list
):
def
terminate_instances
(
module
,
ec2
,
instance_ids
):
"""
Terminates a list of instances
...
...
@@ -462,13 +473,18 @@ def terminate_instances(module, ec2, termination_list):
"changed" will be set to False.
"""
instance_ids
=
[
str
(
inst
[
'id'
])
for
inst
in
termination_list
]
changed
=
False
instance_dict_array
=
[]
if
not
isinstance
(
instance_ids
,
list
)
or
len
(
instance_ids
)
<
1
:
module
.
fail_json
(
msg
=
'instance_ids should be a list of instances, aborting'
)
terminated_instance_ids
=
[]
for
res
in
ec2
.
get_all_instances
(
instance_ids
):
for
inst
in
res
.
instances
:
if
inst
.
state
==
'running'
:
terminated_instance_ids
.
append
(
inst
.
id
)
instance_dict_array
.
append
(
get_instance_info
(
inst
))
try
:
ec2
.
terminate_instances
([
inst
.
id
])
...
...
@@ -476,7 +492,7 @@ def terminate_instances(module, ec2, termination_list):
module
.
fail_json
(
msg
=
'Unable to terminate instance {0}, error: {1}'
.
format
(
inst
.
id
,
e
))
changed
=
True
return
(
changed
,
instance_dict_array
)
return
(
changed
,
instance_dict_array
,
terminated_instance_ids
)
...
...
@@ -505,7 +521,8 @@ def main():
instance_tags
=
dict
(),
vpc_subnet_id
=
dict
(),
private_ip
=
dict
(),
termination_list
=
dict
(
type
=
'list'
)
instance_ids
=
dict
(
type
=
'list'
),
state
=
dict
(
default
=
'present'
),
)
)
...
...
@@ -540,23 +557,23 @@ def main():
except
boto
.
exception
.
NoAuthHandlerFound
,
e
:
module
.
fail_json
(
msg
=
str
(
e
))
if
termination_list
:
if
not
isinstance
(
termination_list
,
list
):
if
module
.
params
.
get
(
'state'
)
==
'absent'
:
instance_ids
=
module
.
params
.
get
(
'instance_ids'
)
if
not
isinstance
(
instance_ids
,
list
):
module
.
fail_json
(
msg
=
'termination_list needs to be a list of instances to terminate'
)
(
changed
,
instance_dict_array
)
=
terminate_instances
(
module
,
ec2
,
termination_list
)
else
:
(
changed
,
instance_dict_array
,
new_instance_ids
)
=
terminate_instances
(
module
,
ec2
,
instance_ids
)
elif
module
.
params
.
get
(
'state'
)
==
'present'
:
# Changed is always set to true when provisioning new instances
changed
=
True
if
not
module
.
params
.
get
(
'key_name'
):
module
.
fail_json
(
msg
=
'key_name parameter is required for new instance'
)
if
not
module
.
params
.
get
(
'image'
):
module
.
fail_json
(
msg
=
'image parameter is required for new instance'
)
instance_dict_array
=
create_instances
(
module
,
ec2
)
(
instance_dict_array
,
new_instance_ids
)
=
create_instances
(
module
,
ec2
)
module
.
exit_json
(
changed
=
True
,
instances
=
instance_dict_array
)
module
.
exit_json
(
changed
=
True
,
instance
_ids
=
new_instance_ids
,
instance
s
=
instance_dict_array
)
# this is magic, see lib/ansible/module_common.py
...
...
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