mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 18:50:21 -07:00
[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
This commit is contained in:
parent
b3abab1bd5
commit
1699c9ea48
1 changed files with 21 additions and 11 deletions
|
@ -78,6 +78,8 @@ EXAMPLES = '''
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
import traceback
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import boto.ec2.elb
|
import boto.ec2.elb
|
||||||
from boto.ec2.tag import Tag
|
from boto.ec2.tag import Tag
|
||||||
|
@ -201,12 +203,15 @@ class ElbInformation(object):
|
||||||
|
|
||||||
|
|
||||||
def list_elbs(self):
|
def list_elbs(self):
|
||||||
elb_array = []
|
elb_array, token = [], None
|
||||||
|
|
||||||
|
while True:
|
||||||
try:
|
try:
|
||||||
all_elbs = self.connection.get_all_load_balancers()
|
all_elbs = self.connection.get_all_load_balancers(marker=token)
|
||||||
|
token = all_elbs.next_token
|
||||||
except BotoServerError as err:
|
except BotoServerError as err:
|
||||||
self.module.fail_json(msg = "%s: %s" % (err.error_code, err.error_message))
|
self.module.fail_json(msg = "%s: %s" % (err.error_code, err.error_message),
|
||||||
|
exception=traceback.format_exc())
|
||||||
|
|
||||||
if all_elbs:
|
if all_elbs:
|
||||||
if self.names:
|
if self.names:
|
||||||
|
@ -214,7 +219,12 @@ class ElbInformation(object):
|
||||||
if existing_lb.name in self.names:
|
if existing_lb.name in self.names:
|
||||||
elb_array.append(existing_lb)
|
elb_array.append(existing_lb)
|
||||||
else:
|
else:
|
||||||
elb_array = all_elbs
|
elb_array.extend(all_elbs)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
if token is None:
|
||||||
|
break
|
||||||
|
|
||||||
return list(map(self._get_elb_info, elb_array))
|
return list(map(self._get_elb_info, elb_array))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue