Merge pull request #2484 from bcoca/ec2_elb_get_really_all

Ec2 elb get really all items
This commit is contained in:
Brian Coca 2015-11-17 12:20:51 -08:00
commit 2c92fc4d3c

View file

@ -50,10 +50,10 @@ options:
choices: [ "yes", "no" ] choices: [ "yes", "no" ]
wait: wait:
description: description:
- Wait for instance registration or deregistration to complete successfully before returning. - Wait for instance registration or deregistration to complete successfully before returning.
required: false required: false
default: yes default: yes
choices: [ "yes", "no" ] choices: [ "yes", "no" ]
validate_certs: validate_certs:
description: description:
- When set to "no", SSL certificates will not be validated for boto versions >= 2.6.0. - When set to "no", SSL certificates will not be validated for boto versions >= 2.6.0.
@ -87,7 +87,7 @@ roles:
- myrole - myrole
post_tasks: post_tasks:
- name: Instance Register - name: Instance Register
local_action: local_action:
module: ec2_elb module: ec2_elb
instance_id: "{{ ansible_ec2_instance_id }}" instance_id: "{{ ansible_ec2_instance_id }}"
ec2_elbs: "{{ item }}" ec2_elbs: "{{ item }}"
@ -256,12 +256,23 @@ class ElbManager:
ec2_elbs = self._get_auto_scaling_group_lbs() ec2_elbs = self._get_auto_scaling_group_lbs()
try: try:
elb = connect_to_aws(boto.ec2.elb, self.region, elb = connect_to_aws(boto.ec2.elb, self.region, **self.aws_connect_params)
**self.aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, StandardError), e:
self.module.fail_json(msg=str(e)) self.module.fail_json(msg=str(e))
elbs = elb.get_all_load_balancers() elbs = []
marker = None
while True:
try:
newelbs = elb.get_all_load_balancers(marker=marker)
marker = newelbs.next_marker
if not marker:
break
elbs.extend(newelbs)
except TypeError:
# Older version of boto do not allow for params
elbs = elb.get_all_load_balancers()
break
if ec2_elbs: if ec2_elbs:
lbs = sorted(lb for lb in elbs if lb.name in ec2_elbs) lbs = sorted(lb for lb in elbs if lb.name in ec2_elbs)
@ -302,8 +313,7 @@ class ElbManager:
def _get_instance(self): def _get_instance(self):
"""Returns a boto.ec2.InstanceObject for self.instance_id""" """Returns a boto.ec2.InstanceObject for self.instance_id"""
try: try:
ec2 = connect_to_aws(boto.ec2, self.region, ec2 = connect_to_aws(boto.ec2, self.region, **self.aws_connect_params)
**self.aws_connect_params)
except (boto.exception.NoAuthHandlerFound, StandardError), e: except (boto.exception.NoAuthHandlerFound, StandardError), e:
self.module.fail_json(msg=str(e)) self.module.fail_json(msg=str(e))
return ec2.get_only_instances(instance_ids=[self.instance_id])[0] return ec2.get_only_instances(instance_ids=[self.instance_id])[0]
@ -330,7 +340,7 @@ def main():
region, ec2_url, aws_connect_params = get_aws_connection_info(module) region, ec2_url, aws_connect_params = get_aws_connection_info(module)
if not region: if not region:
module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file") module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")
ec2_elbs = module.params['ec2_elbs'] ec2_elbs = module.params['ec2_elbs']
@ -342,8 +352,7 @@ def main():
module.fail_json(msg="ELBs are required for registration") module.fail_json(msg="ELBs are required for registration")
instance_id = module.params['instance_id'] instance_id = module.params['instance_id']
elb_man = ElbManager(module, instance_id, ec2_elbs, elb_man = ElbManager(module, instance_id, ec2_elbs, region=region, **aws_connect_params)
region=region, **aws_connect_params)
if ec2_elbs is not None: if ec2_elbs is not None:
for elb in ec2_elbs: for elb in ec2_elbs: