From 1699c9ea4809fb85a8c95d60724b6d182125cc4e Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Mon, 27 Feb 2017 16:42:23 -0500 Subject: [PATCH] [cloud] ec2_elb_facts fails on accounts with to many ELBs (#21602) The list_elbs call to boto doesn't use any pagination, so any time there are more ELBs than the API page size, this module will fail. This change uses the `next_token` attribute of `ResultSet` to check if there are still more ELBs to return. Fixes #21361 --- .../modules/cloud/amazon/ec2_elb_facts.py | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_elb_facts.py b/lib/ansible/modules/cloud/amazon/ec2_elb_facts.py index 017b28e01b..bdd8a13ad0 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_elb_facts.py +++ b/lib/ansible/modules/cloud/amazon/ec2_elb_facts.py @@ -78,6 +78,8 @@ EXAMPLES = ''' ''' +import traceback + try: import boto.ec2.elb from boto.ec2.tag import Tag @@ -201,20 +203,28 @@ class ElbInformation(object): def list_elbs(self): - elb_array = [] + elb_array, token = [], None - try: - all_elbs = self.connection.get_all_load_balancers() - except BotoServerError as err: - self.module.fail_json(msg = "%s: %s" % (err.error_code, err.error_message)) + while True: + try: + all_elbs = self.connection.get_all_load_balancers(marker=token) + token = all_elbs.next_token + except BotoServerError as err: + self.module.fail_json(msg = "%s: %s" % (err.error_code, err.error_message), + exception=traceback.format_exc()) - if all_elbs: - if self.names: - for existing_lb in all_elbs: - if existing_lb.name in self.names: - elb_array.append(existing_lb) + if all_elbs: + if self.names: + for existing_lb in all_elbs: + if existing_lb.name in self.names: + elb_array.append(existing_lb) + else: + elb_array.extend(all_elbs) else: - elb_array = all_elbs + break + + if token is None: + break return list(map(self._get_elb_info, elb_array))