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
a45b3129
Commit
a45b3129
authored
May 02, 2013
by
John Jarvis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changing arg name for consistency, absent/present for registration
parent
e625155c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
18 deletions
+18
-18
library/cloud/ec2_elb
+18
-18
No files found.
library/cloud/ec2_elb
View file @
a45b3129
...
...
@@ -28,7 +28,7 @@ version_added: "1.2"
requirements: [ "boto" ]
author: John Jarvis
options:
action
:
state
:
description:
- register or deregister the instance
required: true
...
...
@@ -38,7 +38,7 @@ options:
- EC2 Instance ID
required: true
e
lb_name
s:
e
c2_elb
s:
description:
- List of ELB names, required for registration. The elb_ec2 fact should be used if there was a previous de-register.
required: false
...
...
@@ -65,7 +65,7 @@ pre_tasks:
local_action: ec2_elb
args:
instance_id: "{{ ansible_ec2_instance_id }}"
action: 'deregister
'
state: 'absent
'
roles:
- myrole
post_tasks:
...
...
@@ -73,8 +73,8 @@ post_tasks:
local_action: ec2_elb
args:
instance_id: "{{ ansible_ec2_instance_id }}"
e
lb_name
s: "{{ ec2_elbs }}"
action: 'register
'
e
c2_elb
s: "{{ ec2_elbs }}"
state: 'present
'
"""
import
time
...
...
@@ -91,13 +91,13 @@ except ImportError:
class
ElbManager
:
"""Handles EC2 instance ELB registration and de-registration"""
def
__init__
(
self
,
module
,
instance_id
=
None
,
e
lb_name
s
=
None
,
def
__init__
(
self
,
module
,
instance_id
=
None
,
e
c2_elb
s
=
None
,
ec2_access_key
=
None
,
ec2_secret_key
=
None
):
self
.
ec2_access_key
=
ec2_access_key
self
.
ec2_secret_key
=
ec2_secret_key
self
.
module
=
module
self
.
instance_id
=
instance_id
self
.
lbs
=
self
.
_get_instance_lbs
(
e
lb_name
s
)
self
.
lbs
=
self
.
_get_instance_lbs
(
e
c2_elb
s
)
# if there are no ELBs to operate on
# there will be no changes made
if
len
(
self
.
lbs
)
>
0
:
...
...
@@ -133,7 +133,7 @@ class ElbManager:
else
:
time
.
sleep
(
1
)
def
_get_instance_lbs
(
self
,
e
lb_name
s
=
None
):
def
_get_instance_lbs
(
self
,
e
c2_elb
s
=
None
):
"""Returns a list of ELBs attached to self.instance_id"""
try
:
...
...
@@ -142,8 +142,8 @@ class ElbManager:
self
.
module
.
fail_json
(
msg
=
str
(
e
))
elbs
=
elb
.
get_all_load_balancers
()
if
e
lb_name
s
:
lbs
=
sorted
(
lb
for
lb
in
elbs
if
lb
.
name
in
e
lb_name
s
)
if
e
c2_elb
s
:
lbs
=
sorted
(
lb
for
lb
in
elbs
if
lb
.
name
in
e
c2_elb
s
)
else
:
lbs
=
[]
for
lb
in
elbs
:
...
...
@@ -157,10 +157,10 @@ def main():
module
=
AnsibleModule
(
argument_spec
=
dict
(
action
=
{
'required'
:
True
,
'choices'
:
[
'
register'
,
'deregister
'
]},
state
=
{
'required'
:
True
,
'choices'
:
[
'
present'
,
'absent
'
]},
instance_id
=
{
'required'
:
True
},
e
lb_name
s
=
{
'default'
:
None
,
'required'
:
False
},
e
c2_elb
s
=
{
'default'
:
None
,
'required'
:
False
},
ec2_secret_key
=
{
'default'
:
None
,
'aliases'
:
[
'EC2_SECRET_KEY'
]},
ec2_access_key
=
{
'default'
:
None
,
'aliases'
:
[
'EC2_ACCESS_KEY'
]}
)
...
...
@@ -168,9 +168,9 @@ def main():
ec2_secret_key
=
module
.
params
[
'ec2_secret_key'
]
ec2_access_key
=
module
.
params
[
'ec2_access_key'
]
e
lb_names
=
module
.
params
[
'elb_name
s'
]
e
c2_elbs
=
module
.
params
[
'ec2_elb
s'
]
if
module
.
params
[
'
action'
]
==
'register'
and
'elb_name
s'
not
in
module
.
params
:
if
module
.
params
[
'
state'
]
==
'register'
and
'ec2_elb
s'
not
in
module
.
params
:
module
.
fail_json
(
msg
=
"ELBs are required for registration"
)
if
not
ec2_secret_key
and
'EC2_SECRET_KEY'
in
os
.
environ
:
...
...
@@ -179,12 +179,12 @@ def main():
ec2_access_key
=
os
.
environ
[
'EC2_ACCESS_KEY'
]
instance_id
=
module
.
params
[
'instance_id'
]
elb_man
=
ElbManager
(
module
,
instance_id
,
e
lb_name
s
,
ec2_access_key
,
elb_man
=
ElbManager
(
module
,
instance_id
,
e
c2_elb
s
,
ec2_access_key
,
ec2_secret_key
)
if
module
.
params
[
'
action
'
]
==
'register'
:
if
module
.
params
[
'
state
'
]
==
'register'
:
elb_man
.
register
()
elif
module
.
params
[
'
action
'
]
==
'deregister'
:
elif
module
.
params
[
'
state
'
]
==
'deregister'
:
elb_man
.
deregister
()
ansible_facts
=
{
'ec2_elbs'
:
[
lb
.
name
for
lb
in
elb_man
.
lbs
]}
...
...
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