From 10b3279691517cdf57b97635ca9c4c11d73ad69e Mon Sep 17 00:00:00 2001 From: jillr Date: Mon, 2 Mar 2020 19:25:18 +0000 Subject: [PATCH 01/32] Initial commit This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/eb75681585a23ea79e642b86a0f8e64e0f40a6d7 --- plugins/modules/elb_classic_lb_info.py | 217 +++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 plugins/modules/elb_classic_lb_info.py diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py new file mode 100644 index 00000000000..f8c7a12f6e8 --- /dev/null +++ b/plugins/modules/elb_classic_lb_info.py @@ -0,0 +1,217 @@ +#!/usr/bin/python +# +# This is a free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This Ansible library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this library. If not, see . + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + + +DOCUMENTATION = ''' +--- +module: elb_classic_lb_info +short_description: Gather information about EC2 Elastic Load Balancers in AWS +description: + - Gather information about EC2 Elastic Load Balancers in AWS + - This module was called C(elb_classic_lb_facts) before Ansible 2.9. The usage did not change. +author: + - "Michael Schultz (@mjschultz)" + - "Fernando Jose Pando (@nand0p)" +options: + names: + description: + - List of ELB names to gather information about. Pass this option to gather information about a set of ELBs, otherwise, all ELBs are returned. + type: list +extends_documentation_fragment: +- ansible.amazon.aws +- ansible.amazon.ec2 + +requirements: + - botocore + - boto3 +''' + +EXAMPLES = ''' +# Note: These examples do not set authentication details, see the AWS Guide for details. +# Output format tries to match ec2_elb_lb module input parameters + +# Gather information about all ELBs +- elb_classic_lb_info: + register: elb_info + +- debug: + msg: "{{ item.dns_name }}" + loop: "{{ elb_info.elbs }}" + +# Gather information about a particular ELB +- elb_classic_lb_info: + names: frontend-prod-elb + register: elb_info + +- debug: + msg: "{{ elb_info.elbs.0.dns_name }}" + +# Gather information about a set of ELBs +- elb_classic_lb_info: + names: + - frontend-prod-elb + - backend-prod-elb + register: elb_info + +- debug: + msg: "{{ item.dns_name }}" + loop: "{{ elb_info.elbs }}" + +''' + +RETURN = ''' +elbs: + description: a list of load balancers + returned: always + type: list + sample: + elbs: + - attributes: + access_log: + enabled: false + connection_draining: + enabled: true + timeout: 300 + connection_settings: + idle_timeout: 60 + cross_zone_load_balancing: + enabled: true + availability_zones: + - "us-east-1a" + - "us-east-1b" + - "us-east-1c" + - "us-east-1d" + - "us-east-1e" + backend_server_description: [] + canonical_hosted_zone_name: test-lb-XXXXXXXXXXXX.us-east-1.elb.amazonaws.com + canonical_hosted_zone_name_id: XXXXXXXXXXXXXX + created_time: 2017-08-23T18:25:03.280000+00:00 + dns_name: test-lb-XXXXXXXXXXXX.us-east-1.elb.amazonaws.com + health_check: + healthy_threshold: 10 + interval: 30 + target: HTTP:80/index.html + timeout: 5 + unhealthy_threshold: 2 + instances: [] + instances_inservice: [] + instances_inservice_count: 0 + instances_outofservice: [] + instances_outofservice_count: 0 + instances_unknownservice: [] + instances_unknownservice_count: 0 + listener_descriptions: + - listener: + instance_port: 80 + instance_protocol: HTTP + load_balancer_port: 80 + protocol: HTTP + policy_names: [] + load_balancer_name: test-lb + policies: + app_cookie_stickiness_policies: [] + lb_cookie_stickiness_policies: [] + other_policies: [] + scheme: internet-facing + security_groups: + - sg-29d13055 + source_security_group: + group_name: default + owner_alias: XXXXXXXXXXXX + subnets: + - subnet-XXXXXXXX + - subnet-XXXXXXXX + tags: {} + vpc_id: vpc-c248fda4 +''' + +from ansible_collections.ansible.amazon.plugins.module_utils.aws.core import AnsibleAWSModule +from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import ( + AWSRetry, + camel_dict_to_snake_dict, + boto3_tag_list_to_ansible_dict +) + +try: + import botocore +except ImportError: + pass # caught by AnsibleAWSModule + + +@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +def list_elbs(connection, names): + paginator = connection.get_paginator('describe_load_balancers') + load_balancers = paginator.paginate(LoadBalancerNames=names).build_full_result().get('LoadBalancerDescriptions', []) + results = [] + + for lb in load_balancers: + description = camel_dict_to_snake_dict(lb) + name = lb['LoadBalancerName'] + instances = lb.get('Instances', []) + description['tags'] = get_tags(connection, name) + description['instances_inservice'], description['instances_inservice_count'] = lb_instance_health(connection, name, instances, 'InService') + description['instances_outofservice'], description['instances_outofservice_count'] = lb_instance_health(connection, name, instances, 'OutOfService') + description['instances_unknownservice'], description['instances_unknownservice_count'] = lb_instance_health(connection, name, instances, 'Unknown') + description['attributes'] = get_lb_attributes(connection, name) + results.append(description) + return results + + +def get_lb_attributes(connection, name): + attributes = connection.describe_load_balancer_attributes(LoadBalancerName=name).get('LoadBalancerAttributes', {}) + return camel_dict_to_snake_dict(attributes) + + +def get_tags(connection, load_balancer_name): + tags = connection.describe_tags(LoadBalancerNames=[load_balancer_name])['TagDescriptions'] + if not tags: + return {} + return boto3_tag_list_to_ansible_dict(tags[0]['Tags']) + + +def lb_instance_health(connection, load_balancer_name, instances, state): + instance_states = connection.describe_instance_health(LoadBalancerName=load_balancer_name, Instances=instances).get('InstanceStates', []) + instate = [instance['InstanceId'] for instance in instance_states if instance['State'] == state] + return instate, len(instate) + + +def main(): + argument_spec = dict( + names={'default': [], 'type': 'list'} + ) + module = AnsibleAWSModule(argument_spec=argument_spec, + supports_check_mode=True) + if module._name == 'elb_classic_lb_facts': + module.deprecate("The 'elb_classic_lb_facts' module has been renamed to 'elb_classic_lb_info'", version='2.13') + + connection = module.client('elb') + + try: + elbs = list_elbs(connection, module.params.get('names')) + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: + module.fail_json_aws(e, msg="Failed to get load balancer information.") + + module.exit_json(elbs=elbs) + + +if __name__ == '__main__': + main() From 0ff7fbc32f17af39a2d3e3d6d655cbdbc13aa15d Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Wed, 25 Mar 2020 15:39:40 -0700 Subject: [PATCH 02/32] Rename collection (#12) * Rename core collection Rename references to ansible.amazon to amazon.aws. * Rename community.amazon to community.aws Fix pep8 line lengths for rewritten amazon.aws imports * Missed a path in shippable.sh * Dependency repos moved This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/235c5db571cc45db5839476c94356c9b91e1f228 --- plugins/modules/elb_classic_lb_info.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index f8c7a12f6e8..42be1a2265f 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -37,8 +37,8 @@ - List of ELB names to gather information about. Pass this option to gather information about a set of ELBs, otherwise, all ELBs are returned. type: list extends_documentation_fragment: -- ansible.amazon.aws -- ansible.amazon.ec2 +- amazon.aws.aws +- amazon.aws.ec2 requirements: - botocore @@ -144,8 +144,8 @@ vpc_id: vpc-c248fda4 ''' -from ansible_collections.ansible.amazon.plugins.module_utils.aws.core import AnsibleAWSModule -from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import ( +from ansible_collections.amazon.aws.plugins.module_utils.aws.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ( AWSRetry, camel_dict_to_snake_dict, boto3_tag_list_to_ansible_dict From 342c2d8388915d9ce6c6ca6fff04351184ac9305 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 29 Apr 2020 23:19:49 +0200 Subject: [PATCH 03/32] Fix more doc issues where strings are parsed as datetimes by YAML parser. (#55) This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/4a0e1a4d8797e71dbb39ab04d14b41133d01c979 --- plugins/modules/elb_classic_lb_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 42be1a2265f..8708aa95b32 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -104,7 +104,7 @@ backend_server_description: [] canonical_hosted_zone_name: test-lb-XXXXXXXXXXXX.us-east-1.elb.amazonaws.com canonical_hosted_zone_name_id: XXXXXXXXXXXXXX - created_time: 2017-08-23T18:25:03.280000+00:00 + created_time: '2017-08-23T18:25:03.280000+00:00' dns_name: test-lb-XXXXXXXXXXXX.us-east-1.elb.amazonaws.com health_check: healthy_threshold: 10 From 14bd72d26ddd353ad48a90fd9c255aea984c9dd2 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Tue, 19 May 2020 16:06:12 -0700 Subject: [PATCH 04/32] Remove METADATA and cleanup galaxy.yml (#70) * Remove ANSIBLE_METADATA entirely, see ansible/ansible/pull/69454. Remove `license` field from galaxy.yml, in favor of `license_file`. This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/05672a64e2362cc2d865b5af6a57da6bc3cd08e3 --- plugins/modules/elb_classic_lb_info.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 8708aa95b32..a38aee6b253 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -16,10 +16,6 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - DOCUMENTATION = ''' --- From 10f6460371089396617454de0cc74e584b7231de Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Tue, 16 Jun 2020 11:23:52 -0700 Subject: [PATCH 05/32] Collections related fixes for CI (#96) * Update module deprecations Switch version to `removed_at_date` * Don't install amazon.aws from galaxy We've been using galaxy to install amazon.aws in shippable, but that doesn't really work if we aren't publising faster. Get that collection from git so it is most up to date. * We need to declare python test deps now * missed a python dep This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/7cd211e9383db26bc2aa4cc06e657cf60ed0acc0 --- plugins/modules/elb_classic_lb_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index a38aee6b253..915bf19aece 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -197,7 +197,7 @@ def main(): module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) if module._name == 'elb_classic_lb_facts': - module.deprecate("The 'elb_classic_lb_facts' module has been renamed to 'elb_classic_lb_info'", version='2.13') + module.deprecate("The 'elb_classic_lb_facts' module has been renamed to 'elb_classic_lb_info'", date='2021-12-01', collection_name='community.aws') connection = module.client('elb') From 65af49f066c6e341d0b530064e2b38fced50fbf0 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 17 Jun 2020 01:24:54 +0530 Subject: [PATCH 06/32] Update Examples with FQCN (#67) Updated module examples with FQCN Signed-off-by: Abhijeet Kasurde This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/98173aefbbceed7fc0d9db62687b73f96a55a999 --- plugins/modules/elb_classic_lb_info.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 915bf19aece..9341cb59b4b 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -43,10 +43,10 @@ EXAMPLES = ''' # Note: These examples do not set authentication details, see the AWS Guide for details. -# Output format tries to match ec2_elb_lb module input parameters +# Output format tries to match amazon.aws.ec2_elb_lb module input parameters # Gather information about all ELBs -- elb_classic_lb_info: +- community.aws.elb_classic_lb_info: register: elb_info - debug: @@ -54,7 +54,7 @@ loop: "{{ elb_info.elbs }}" # Gather information about a particular ELB -- elb_classic_lb_info: +- community.aws.elb_classic_lb_info: names: frontend-prod-elb register: elb_info @@ -62,7 +62,7 @@ msg: "{{ elb_info.elbs.0.dns_name }}" # Gather information about a set of ELBs -- elb_classic_lb_info: +- community.aws.elb_classic_lb_info: names: - frontend-prod-elb - backend-prod-elb From fa8ea78019da246c924214973450c2f79f597f5b Mon Sep 17 00:00:00 2001 From: flowerysong Date: Tue, 16 Jun 2020 19:30:00 -0400 Subject: [PATCH 07/32] Update module_utils paths to remove aws subdir (#23) Co-authored-by: Ezekiel Hendrickson This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/10853d9441a586ba177006dd889325cfb24a3dd6 --- plugins/modules/elb_classic_lb_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 9341cb59b4b..4b2a2db64bb 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -140,7 +140,7 @@ vpc_id: vpc-c248fda4 ''' -from ansible_collections.amazon.aws.plugins.module_utils.aws.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ( AWSRetry, camel_dict_to_snake_dict, From 4085f5465e8bc4c718907eb11e6eea1bc2f37990 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Wed, 17 Jun 2020 09:31:32 -0700 Subject: [PATCH 08/32] Update docs (#99) * Update docs Remove .git from repo url so links in readme will generate correctly Add required ansible version Run latest version of add_docs.py Add version_added string to modules * galaxy.yml was missing authors This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/96ee268e5267f5b12c3d59892bc1279f75aa3135 --- plugins/modules/elb_classic_lb_info.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 4b2a2db64bb..da8f6c5af11 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -20,6 +20,7 @@ DOCUMENTATION = ''' --- module: elb_classic_lb_info +version_added: 1.0.0 short_description: Gather information about EC2 Elastic Load Balancers in AWS description: - Gather information about EC2 Elastic Load Balancers in AWS From c58e40d4db65bffa7dec200791a971de3a49f9ad Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 16 Jul 2020 01:31:41 +0530 Subject: [PATCH 09/32] Docs: sanity fixes (#133) Signed-off-by: Abhijeet Kasurde This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/059cf9efc95bb976de21ab4f8e4d9ddd001983fc --- plugins/modules/elb_classic_lb_info.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index da8f6c5af11..88d44ee8125 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -17,7 +17,7 @@ __metaclass__ = type -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: elb_classic_lb_info version_added: 1.0.0 @@ -33,6 +33,7 @@ description: - List of ELB names to gather information about. Pass this option to gather information about a set of ELBs, otherwise, all ELBs are returned. type: list + elements: str extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 @@ -42,7 +43,7 @@ - boto3 ''' -EXAMPLES = ''' +EXAMPLES = r''' # Note: These examples do not set authentication details, see the AWS Guide for details. # Output format tries to match amazon.aws.ec2_elb_lb module input parameters @@ -75,7 +76,7 @@ ''' -RETURN = ''' +RETURN = r''' elbs: description: a list of load balancers returned: always @@ -193,7 +194,7 @@ def lb_instance_health(connection, load_balancer_name, instances, state): def main(): argument_spec = dict( - names={'default': [], 'type': 'list'} + names={'default': [], 'type': 'list', 'elements': 'str'} ) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) From 80dd85ebd30d14c34777efd185da5e4c94ca8fa2 Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Fri, 17 Jul 2020 21:10:09 +0300 Subject: [PATCH 10/32] aws modules: fix examples to use FQCN for builtin modules/plugins (#144) This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/92bebdd5ab3019bbdeee55e8a69c9d903deeac49 --- plugins/modules/elb_classic_lb_info.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 88d44ee8125..12a6a43771a 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -51,7 +51,7 @@ - community.aws.elb_classic_lb_info: register: elb_info -- debug: +- ansible.builtin.debug: msg: "{{ item.dns_name }}" loop: "{{ elb_info.elbs }}" @@ -60,7 +60,7 @@ names: frontend-prod-elb register: elb_info -- debug: +- ansible.builtin.debug: msg: "{{ elb_info.elbs.0.dns_name }}" # Gather information about a set of ELBs @@ -70,7 +70,7 @@ - backend-prod-elb register: elb_info -- debug: +- ansible.builtin.debug: msg: "{{ item.dns_name }}" loop: "{{ elb_info.elbs }}" From 25632f385cef5a3f24c3957cc717b87bab21a430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Magalh=C3=A3es?= <4622652+pjrm@users.noreply.github.com> Date: Sun, 14 Mar 2021 14:27:15 +0000 Subject: [PATCH 11/32] AWS ELB: Return empty list when no load balancer name was found (#215) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When trying to describe a LoadBalancer that doesn't exist, the module crash. Instead of that behavior, this commit will return an empty list when no load balancer is found, allowing to deal next tasks by reading the output of the module. Co-authored-by: Pedro Magalhães This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/3d5ffdc5efa90fde935336a5834e54a1d1f4529d --- plugins/modules/elb_classic_lb_info.py | 32 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 12a6a43771a..a1a0c39e042 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -142,7 +142,7 @@ vpc_id: vpc-c248fda4 ''' -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ( AWSRetry, camel_dict_to_snake_dict, @@ -154,14 +154,17 @@ except ImportError: pass # caught by AnsibleAWSModule +MAX_AWS_RETRIES = 5 +MAX_AWS_DELAY = 5 -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) -def list_elbs(connection, names): - paginator = connection.get_paginator('describe_load_balancers') - load_balancers = paginator.paginate(LoadBalancerNames=names).build_full_result().get('LoadBalancerDescriptions', []) + +def list_elbs(connection, load_balancer_names): results = [] - for lb in load_balancers: + for load_balancer_name in load_balancer_names: + lb = get_lb(connection, load_balancer_name) + if not lb: + continue description = camel_dict_to_snake_dict(lb) name = lb['LoadBalancerName'] instances = lb.get('Instances', []) @@ -174,13 +177,20 @@ def list_elbs(connection, names): return results -def get_lb_attributes(connection, name): - attributes = connection.describe_load_balancer_attributes(LoadBalancerName=name).get('LoadBalancerAttributes', {}) +def get_lb(connection, load_balancer_name): + try: + return connection.describe_load_balancers(aws_retry=True, LoadBalancerNames=[load_balancer_name])['LoadBalancerDescriptions'][0] + except is_boto3_error_code('LoadBalancerNotFound'): + return [] + + +def get_lb_attributes(connection, load_balancer_name): + attributes = connection.describe_load_balancer_attributes(aws_retry=True, LoadBalancerName=load_balancer_name).get('LoadBalancerAttributes', {}) return camel_dict_to_snake_dict(attributes) def get_tags(connection, load_balancer_name): - tags = connection.describe_tags(LoadBalancerNames=[load_balancer_name])['TagDescriptions'] + tags = connection.describe_tags(aws_retry=True, LoadBalancerNames=[load_balancer_name])['TagDescriptions'] if not tags: return {} return boto3_tag_list_to_ansible_dict(tags[0]['Tags']) @@ -194,14 +204,14 @@ def lb_instance_health(connection, load_balancer_name, instances, state): def main(): argument_spec = dict( - names={'default': [], 'type': 'list', 'elements': 'str'} + names=dict(default=[], type='list', elements='str') ) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) if module._name == 'elb_classic_lb_facts': module.deprecate("The 'elb_classic_lb_facts' module has been renamed to 'elb_classic_lb_info'", date='2021-12-01', collection_name='community.aws') - connection = module.client('elb') + connection = module.client('elb', retry_decorator=AWSRetry.jittered_backoff(retries=MAX_AWS_RETRIES, delay=MAX_AWS_DELAY)) try: elbs = list_elbs(connection, module.params.get('names')) From 7f041205274dd52acf40c5172c7e49b643aac35d Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Thu, 6 May 2021 21:01:46 +0200 Subject: [PATCH 12/32] Update the default module requirements from python 2.6/boto to python 3.6/boto3 This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/c097c55293be0834a2b9d394733ec28965d142d7 --- plugins/modules/elb_classic_lb_info.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index a1a0c39e042..f57f4dd391c 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -37,10 +37,6 @@ extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 - -requirements: - - botocore - - boto3 ''' EXAMPLES = r''' From dae9be7c55075da762331f69897cc9e474b78463 Mon Sep 17 00:00:00 2001 From: christophemorio <49184206+christophemorio@users.noreply.github.com> Date: Sun, 24 Oct 2021 11:15:47 +0200 Subject: [PATCH 13/32] ELB info: return all LB if names is not defined (#693) ELB info: return all LB if names is not defined SUMMARY Documentation says options: names: description: - List of ELB names to gather information about. Pass this option to gather information about a set of ELBs, otherwise, all ELBs are returned. But doing this elb_classic_lb_info returns an empty list. ISSUE TYPE Bugfix Pull Request COMPONENT NAME elb_classic_lb_info ADDITIONAL INFORMATION - hosts: localhost tasks: - community.aws.elb_classic_lb_info: {} register: elb_info - debug: var=elb_info $ ansible-playbook playbook.yaml TASK [community.aws.elb_classic_lb_info] ******** ok: [localhost] TASK [debug] ******** ok: [localhost] => { "elb_info": { "changed": false, "elbs": [], # <-- should return list of all ELB "failed": false } } Reviewed-by: Mark Chappell Reviewed-by: None Reviewed-by: None This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/bebdd7576e1018e4a198afd7babacdfd96b52fe5 --- plugins/modules/elb_classic_lb_info.py | 32 +- .../targets/elb_classic_lb_info/aliases | 1 + .../elb_classic_lb_info/defaults/main.yml | 3 + .../targets/elb_classic_lb_info/meta/main.yml | 3 + .../elb_classic_lb_info/tasks/main.yml | 311 ++++++++++++++++++ .../targets/elb_classic_lb_info/vars/main.yml | 2 + 6 files changed, 343 insertions(+), 9 deletions(-) create mode 100644 tests/integration/targets/elb_classic_lb_info/aliases create mode 100644 tests/integration/targets/elb_classic_lb_info/defaults/main.yml create mode 100644 tests/integration/targets/elb_classic_lb_info/meta/main.yml create mode 100644 tests/integration/targets/elb_classic_lb_info/tasks/main.yml create mode 100644 tests/integration/targets/elb_classic_lb_info/vars/main.yml diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index f57f4dd391c..1afbd49c9dc 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -157,22 +157,36 @@ def list_elbs(connection, load_balancer_names): results = [] + if not load_balancer_names: + for lb in get_all_lb(connection): + results.append(describe_elb(connection, lb)) + for load_balancer_name in load_balancer_names: lb = get_lb(connection, load_balancer_name) if not lb: continue - description = camel_dict_to_snake_dict(lb) - name = lb['LoadBalancerName'] - instances = lb.get('Instances', []) - description['tags'] = get_tags(connection, name) - description['instances_inservice'], description['instances_inservice_count'] = lb_instance_health(connection, name, instances, 'InService') - description['instances_outofservice'], description['instances_outofservice_count'] = lb_instance_health(connection, name, instances, 'OutOfService') - description['instances_unknownservice'], description['instances_unknownservice_count'] = lb_instance_health(connection, name, instances, 'Unknown') - description['attributes'] = get_lb_attributes(connection, name) - results.append(description) + results.append(describe_elb(connection, lb)) return results +def describe_elb(connection, lb): + description = camel_dict_to_snake_dict(lb) + name = lb['LoadBalancerName'] + instances = lb.get('Instances', []) + description['tags'] = get_tags(connection, name) + description['instances_inservice'], description['instances_inservice_count'] = lb_instance_health(connection, name, instances, 'InService') + description['instances_outofservice'], description['instances_outofservice_count'] = lb_instance_health(connection, name, instances, 'OutOfService') + description['instances_unknownservice'], description['instances_unknownservice_count'] = lb_instance_health(connection, name, instances, 'Unknown') + description['attributes'] = get_lb_attributes(connection, name) + return description + + +@AWSRetry.jittered_backoff() +def get_all_lb(connection): + paginator = connection.get_paginator('describe_load_balancers') + return paginator.paginate().build_full_result()['LoadBalancerDescriptions'] + + def get_lb(connection, load_balancer_name): try: return connection.describe_load_balancers(aws_retry=True, LoadBalancerNames=[load_balancer_name])['LoadBalancerDescriptions'][0] diff --git a/tests/integration/targets/elb_classic_lb_info/aliases b/tests/integration/targets/elb_classic_lb_info/aliases new file mode 100644 index 00000000000..4ef4b2067d0 --- /dev/null +++ b/tests/integration/targets/elb_classic_lb_info/aliases @@ -0,0 +1 @@ +cloud/aws diff --git a/tests/integration/targets/elb_classic_lb_info/defaults/main.yml b/tests/integration/targets/elb_classic_lb_info/defaults/main.yml new file mode 100644 index 00000000000..bd059e26ea7 --- /dev/null +++ b/tests/integration/targets/elb_classic_lb_info/defaults/main.yml @@ -0,0 +1,3 @@ +--- +# defaults file for test_ec2_eip +elb_name: 'ansible-test-{{ tiny_prefix }}-ecli' diff --git a/tests/integration/targets/elb_classic_lb_info/meta/main.yml b/tests/integration/targets/elb_classic_lb_info/meta/main.yml new file mode 100644 index 00000000000..1f64f1169a9 --- /dev/null +++ b/tests/integration/targets/elb_classic_lb_info/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + - setup_ec2 diff --git a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml new file mode 100644 index 00000000000..e4cd8144b1e --- /dev/null +++ b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml @@ -0,0 +1,311 @@ +--- +# __Test Info__ +# Create a self signed cert and upload it to AWS +# http://www.akadia.com/services/ssh_test_certificate.html +# http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/ssl-server-cert.html + +# __Test Outline__ +# +# __elb_classic_lb__ +# create test elb with listeners and certificate +# change AZ's +# change listeners +# remove listeners +# remove elb + +# __elb_classic_lb_info_ +# get nonexistent load balancer + +- module_defaults: + group/aws: + region: "{{ ec2_region }}" + ec2_access_key: "{{ ec2_access_key }}" + ec2_secret_key: "{{ ec2_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + block: + + # ============================================================ + # create test elb with listeners, certificate, and health check + + - name: Create ELB + elb_classic_lb: + name: "{{ elb_name }}" + state: present + zones: + - "{{ ec2_region }}a" + - "{{ ec2_region }}b" + listeners: + - protocol: http + load_balancer_port: 80 + instance_port: 80 + - protocol: http + load_balancer_port: 8080 + instance_port: 8080 + health_check: + ping_protocol: http + ping_port: 80 + ping_path: "/index.html" + response_timeout: 5 + interval: 30 + unhealthy_threshold: 2 + healthy_threshold: 10 + register: create + + - assert: + that: + - create is changed + # We rely on these for the info test, make sure they're what we expect + - '"{{ ec2_region }}a" in create.elb.zones' + - '"{{ ec2_region }}b" in create.elb.zones' + - create.elb.health_check.healthy_threshold == 10 + - create.elb.health_check.interval == 30 + - create.elb.health_check.target == "HTTP:80/index.html" + - create.elb.health_check.timeout == 5 + - create.elb.health_check.unhealthy_threshold == 2 + - '[80, 80, "HTTP", "HTTP"] in create.elb.listeners' + - '[8080, 8080, "HTTP", "HTTP"] in create.elb.listeners' + + - name: Get ELB info + elb_classic_lb_info: + names: "{{ elb_name }}" + register: info + + - assert: + that: + - info.elbs|length == 1 + - elb.availability_zones|length == 2 + - '"{{ ec2_region }}a" in elb.availability_zones' + - '"{{ ec2_region }}b" in elb.availability_zones' + - elb.health_check.healthy_threshold == 10 + - elb.health_check.interval == 30 + - elb.health_check.target == "HTTP:80/index.html" + - elb.health_check.timeout == 5 + - elb.health_check.unhealthy_threshold == 2 + - '{"instance_port": 80, "instance_protocol": "HTTP", "load_balancer_port": 80, "protocol": "HTTP"} == listeners[0]' + - '{"instance_port": 8080, "instance_protocol": "HTTP", "load_balancer_port": 8080, "protocol": "HTTP"} == listeners[1]' + vars: + elb: "{{ info.elbs[0] }}" + listeners: "{{ elb.listener_descriptions|map(attribute='listener')|sort(attribute='load_balancer_port') }}" + + # ============================================================ + + # check ports, would be cool, but we are at the mercy of AWS + # to start things in a timely manner + + #- name: check to make sure 80 is listening + # wait_for: host={{ info.elb.dns_name }} port=80 timeout=600 + # register: result + + #- name: assert can connect to port# + # assert: 'result.state == "started"' + + #- name: check to make sure 443 is listening + # wait_for: host={{ info.elb.dns_name }} port=443 timeout=600 + # register: result + + #- name: assert can connect to port# + # assert: 'result.state == "started"' + + # ============================================================ + + # Change AZ's + + - name: Change AZ's + elb_classic_lb: + name: "{{ elb_name }}" + state: present + zones: + - "{{ ec2_region }}c" + listeners: + - protocol: http + load_balancer_port: 80 + instance_port: 80 + purge_zones: yes + health_check: + ping_protocol: http + ping_port: 80 + ping_path: "/index.html" + response_timeout: 5 + interval: 30 + unhealthy_threshold: 2 + healthy_threshold: 10 + register: update_az + + - assert: + that: + - update_az is changed + - update_az.elb.zones[0] == "{{ ec2_region }}c" + + - name: Get ELB info after changing AZ's + elb_classic_lb_info: + names: "{{ elb_name }}" + register: info + + - assert: + that: + - elb.availability_zones|length == 1 + - '"{{ ec2_region }}c" in elb.availability_zones[0]' + vars: + elb: "{{ info.elbs[0] }}" + + # ============================================================ + + # Update AZ's + + - name: Update AZ's + elb_classic_lb: + name: "{{ elb_name }}" + state: present + zones: + - "{{ ec2_region }}a" + - "{{ ec2_region }}b" + - "{{ ec2_region }}c" + listeners: + - protocol: http + load_balancer_port: 80 + instance_port: 80 + purge_zones: yes + register: update_az + + - assert: + that: + - update_az is changed + - '"{{ ec2_region }}a" in update_az.elb.zones' + - '"{{ ec2_region }}b" in update_az.elb.zones' + - '"{{ ec2_region }}c" in update_az.elb.zones' + + - name: Get ELB info after updating AZ's + elb_classic_lb_info: + names: "{{ elb_name }}" + register: info + + - assert: + that: + - elb.availability_zones|length == 3 + - '"{{ ec2_region }}a" in elb.availability_zones' + - '"{{ ec2_region }}b" in elb.availability_zones' + - '"{{ ec2_region }}c" in elb.availability_zones' + vars: + elb: "{{ info.elbs[0] }}" + + # ============================================================ + + # Purge Listeners + + - name: Purge Listeners + elb_classic_lb: + name: "{{ elb_name }}" + state: present + zones: + - "{{ ec2_region }}a" + - "{{ ec2_region }}b" + - "{{ ec2_region }}c" + listeners: + - protocol: http + load_balancer_port: 80 + instance_port: 81 + purge_listeners: yes + register: purge_listeners + + - assert: + that: + - purge_listeners is changed + - '[80, 81, "HTTP", "HTTP"] in purge_listeners.elb.listeners' + - purge_listeners.elb.listeners|length == 1 + + - name: Get ELB info after purging listeners + elb_classic_lb_info: + names: "{{ elb_name }}" + register: info + + - assert: + that: + - elb.listener_descriptions|length == 1 + - '{"instance_port": 81, "instance_protocol": "HTTP", "load_balancer_port": 80, "protocol": "HTTP"} == elb.listener_descriptions[0].listener' + vars: + elb: "{{ info.elbs[0] }}" + + + # ============================================================ + + # add Listeners + + - name: Add Listeners + elb_classic_lb: + name: "{{ elb_name }}" + state: present + zones: + - "{{ ec2_region }}a" + - "{{ ec2_region }}b" + - "{{ ec2_region }}c" + listeners: + - protocol: http + load_balancer_port: 8081 + instance_port: 8081 + purge_listeners: no + register: update_listeners + + - assert: + that: + - update_listeners is changed + - '[80, 81, "HTTP", "HTTP"] in update_listeners.elb.listeners' + - '[8081, 8081, "HTTP", "HTTP"] in update_listeners.elb.listeners' + - update_listeners.elb.listeners|length == 2 + + - name: Get ELB info after adding listeners + elb_classic_lb_info: + names: "{{ elb_name }}" + register: info + + - assert: + that: + - elb.listener_descriptions|length == 2 + - '{"instance_port": 81, "instance_protocol": "HTTP", "load_balancer_port": 80, "protocol": "HTTP"} == listeners[0]' + - '{"instance_port": 8081, "instance_protocol": "HTTP", "load_balancer_port": 8081, "protocol": "HTTP"} == listeners[1]' + vars: + elb: "{{ info.elbs[0] }}" + listeners: "{{ elb.listener_descriptions|map(attribute='listener')|sort(attribute='load_balancer_port') }}" + + # ============================================================ + + # Test getting nonexistent load balancer + - name: get nonexistent load balancer + elb_classic_lb_info: + names: "invalid-elb" + register: info + + - assert: + that: + - info.elbs|length==0 + + # Test getting a valid and nonexistent load balancer + - name: get nonexistent load balancer + elb_classic_lb_info: + names: ["{{ elb_name }}", "invalid-elb"] + register: info + + - assert: + that: + - info.elbs|length==1 + - info.elbs[0].load_balancer_name == elb_name + + # ============================================================ + + - name: get all load balancers + elb_classic_lb_info: + names: "{{ omit }}" + register: info + + - assert: + that: + - info.elbs|length>0 + + always: + + # ============================================================ + - name: remove the test load balancer completely + elb_classic_lb: + name: "{{ elb_name }}" + state: absent + register: result + ignore_errors: true diff --git a/tests/integration/targets/elb_classic_lb_info/vars/main.yml b/tests/integration/targets/elb_classic_lb_info/vars/main.yml new file mode 100644 index 00000000000..79194af1ef5 --- /dev/null +++ b/tests/integration/targets/elb_classic_lb_info/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for test_ec2_elb_lb From acbf8bbf02e3a77629e9ec692085d3c76cd757b4 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Thu, 2 Dec 2021 02:58:06 -0700 Subject: [PATCH 14/32] Remove deprecated "facts" aliases (#814) Remove deprecated "facts" aliases SUMMARY Modules named "facts.py" that do not return ansible_facts were renamed to "info.py" in 2.9. Remove these aliases now that the deprecation period is over. This PR should be included in 3.0.0 of the collection. ISSUE TYPE Bugfix Pull Request COMPONENT NAME *_facts.py Reviewed-by: Mark Chappell Reviewed-by: Jill R Reviewed-by: None This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/68aaa7057be46a3ab36f572fd0013d64653af909 --- plugins/modules/elb_classic_lb_info.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 1afbd49c9dc..25d4eadbf63 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -24,7 +24,6 @@ short_description: Gather information about EC2 Elastic Load Balancers in AWS description: - Gather information about EC2 Elastic Load Balancers in AWS - - This module was called C(elb_classic_lb_facts) before Ansible 2.9. The usage did not change. author: - "Michael Schultz (@mjschultz)" - "Fernando Jose Pando (@nand0p)" @@ -218,8 +217,6 @@ def main(): ) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) - if module._name == 'elb_classic_lb_facts': - module.deprecate("The 'elb_classic_lb_facts' module has been renamed to 'elb_classic_lb_info'", date='2021-12-01', collection_name='community.aws') connection = module.client('elb', retry_decorator=AWSRetry.jittered_backoff(retries=MAX_AWS_RETRIES, delay=MAX_AWS_DELAY)) From 67abbe958e5bafdf7d21e32934ff87c2ac274cf5 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 22 Apr 2022 11:44:07 +0200 Subject: [PATCH 15/32] Integration test dependency cleanup (#1086) Integration test dependency cleanup SUMMARY remove dependencies on setup_remote_tmp_dir where it's not used (often just copy & paste from another test) remove setup_ec2 (no main.yml means it's not doing anything) remove prepare_tests (empty main.yml means it's not doing anything) ISSUE TYPE Feature Pull Request COMPONENT NAME tests/integration/targets ADDITIONAL INFORMATION By cleaning up what we have we reduce the chance of people copying things about "because that's what test XYZ did". Reviewed-by: Alina Buzachis Reviewed-by: Mark Woolley This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/dd12046a1e2d5f39692b1890ff07e06c56b3bf0e --- tests/integration/targets/elb_classic_lb_info/meta/main.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration/targets/elb_classic_lb_info/meta/main.yml b/tests/integration/targets/elb_classic_lb_info/meta/main.yml index 1f64f1169a9..32cf5dda7ed 100644 --- a/tests/integration/targets/elb_classic_lb_info/meta/main.yml +++ b/tests/integration/targets/elb_classic_lb_info/meta/main.yml @@ -1,3 +1 @@ -dependencies: - - prepare_tests - - setup_ec2 +dependencies: [] From f45a5df692788eb7e1a457318bef78fb7ce311c1 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Wed, 5 Oct 2022 17:04:40 +0200 Subject: [PATCH 16/32] Update extends_documentation_fragment with amazon.aws.boto3 (#1459) Update extends_documentation_fragment with amazon.aws.boto3 Depends-On: ansible/ansible-zuul-jobs#1654 SUMMARY As per ansible-collections/amazon.aws#985 add amazon.aws.boto3. ISSUE TYPE Docs Pull Request COMPONENT NAME several Reviewed-by: Jill R Reviewed-by: Mark Chappell Reviewed-by: Markus Bergholz This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/bd3c03fcba0848f593b86309740fa73e986a9646 --- plugins/modules/elb_classic_lb_info.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 25d4eadbf63..4b28fafd388 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -36,6 +36,7 @@ extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 +- amazon.aws.boto3 ''' EXAMPLES = r''' From bfdc098f4dcba8d0af08fb6b4b0f32cb16992dc8 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 2 Nov 2022 11:49:57 +0100 Subject: [PATCH 17/32] Fix non-matching defaults in docs (#1576) Fix non-matching defaults in docs Depends-On: #1579 SUMMARY Fix various non-matching default values exposed by ansible/ansible#79267. ISSUE TYPE Docs Pull Request COMPONENT NAME various Reviewed-by: Markus Bergholz This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/15568f01dc839983dc5c79b78f26b53a93fa72ee --- plugins/modules/elb_classic_lb_info.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 4b28fafd388..4cbeb95890d 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -33,6 +33,7 @@ - List of ELB names to gather information about. Pass this option to gather information about a set of ELBs, otherwise, all ELBs are returned. type: list elements: str + default: [] extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 From 620f5064ddbce0cb168ba75e5c832f2c0b8abeaa Mon Sep 17 00:00:00 2001 From: Bikouo Aubin <79859644+abikouo@users.noreply.github.com> Date: Tue, 10 Jan 2023 19:22:13 +0100 Subject: [PATCH 18/32] Ansible User-Agent identification for community.aws (#1632) Ansible User-Agent identification for community.aws SUMMARY The value will be similar to this APN/1.0 Ansible/2.14.1 community.aws/6.0.0-dev0 ISSUE TYPE Feature Pull Request Reviewed-by: Mark Chappell Reviewed-by: Bikouo Aubin Reviewed-by: Alina Buzachis This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/a8cbce24071bcc62fe4594c38aff1baf18bd2862 --- plugins/modules/elb_classic_lb_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 4cbeb95890d..9298085e28f 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -139,7 +139,8 @@ vpc_id: vpc-c248fda4 ''' -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code +from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ( AWSRetry, camel_dict_to_snake_dict, From b968c5197c02beccebdc00f13bd0dddc24fc8618 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 8 Mar 2023 12:07:26 +0100 Subject: [PATCH 19/32] Cleanup headers and imports (#1738) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleanup headers and imports SUMMARY Mass update of imports, docs fragments and file headers Many of the amazon.aws module_utils and docs fragments got moved about, update community.aws to reflect this. Consistently apply the comment headers as documented at https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_documenting.html#python-shebang-utf-8-coding ISSUE TYPE Docs Pull Request Feature Pull Request COMPONENT NAME ADDITIONAL INFORMATION Header cleanup based upon: https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_documenting.html#python-shebang-utf-8-coding Begin your Ansible module with #!/usr/bin/python - this “shebang” allows ansible_python_interpreter to work. Follow the shebang immediately with # -*- coding: utf-8 -*- to clarify that the file is UTF-8 encoded. and https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_documenting.html#copyright-and-license After the shebang and UTF-8 coding, add a copyright line with the original copyright holder and a license declaration. The license declaration should be ONLY one line, not the full GPL prefix. ... Additions to the module (for instance, rewrites) are not permitted to add additional copyright lines other than the default copyright statement if missing: Reviewed-by: Alina Buzachis This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/a4f20bf114bfab19b1c84c4ecf42efd5614ab80c --- plugins/modules/elb_classic_lb_info.py | 60 +++++++++++--------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 9298085e28f..3d3d43d4e71 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -1,29 +1,16 @@ #!/usr/bin/python -# -# This is a free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This Ansible library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library. If not, see . - -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - - -DOCUMENTATION = r''' +# -*- coding: utf-8 -*- + +# Copyright: Contributors to the Ansible project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +DOCUMENTATION = r""" --- module: elb_classic_lb_info version_added: 1.0.0 short_description: Gather information about EC2 Elastic Load Balancers in AWS description: - - Gather information about EC2 Elastic Load Balancers in AWS + - Gather information about EC2 Elastic Load Balancers in AWS author: - "Michael Schultz (@mjschultz)" - "Fernando Jose Pando (@nand0p)" @@ -35,12 +22,12 @@ elements: str default: [] extends_documentation_fragment: -- amazon.aws.aws -- amazon.aws.ec2 -- amazon.aws.boto3 -''' + - amazon.aws.common.modules + - amazon.aws.region.modules + - amazon.aws.boto3 +""" -EXAMPLES = r''' +EXAMPLES = r""" # Note: These examples do not set authentication details, see the AWS Guide for details. # Output format tries to match amazon.aws.ec2_elb_lb module input parameters @@ -71,9 +58,9 @@ msg: "{{ item.dns_name }}" loop: "{{ elb_info.elbs }}" -''' +""" -RETURN = r''' +RETURN = r""" elbs: description: a list of load balancers returned: always @@ -137,21 +124,22 @@ - subnet-XXXXXXXX tags: {} vpc_id: vpc-c248fda4 -''' - -from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ( - AWSRetry, - camel_dict_to_snake_dict, - boto3_tag_list_to_ansible_dict -) +""" try: import botocore except ImportError: pass # caught by AnsibleAWSModule +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + +from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict + +from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule + + MAX_AWS_RETRIES = 5 MAX_AWS_DELAY = 5 From 7e591108990f8b2d2704ae04c6bfb7659d7c885e Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 26 Apr 2023 19:26:07 +0200 Subject: [PATCH 20/32] Big Black PR (#1784) * Black prep * Black * changelog * Fix pylint unused-import in tests * Split SSM connection plugin changes * disable glue tests - bucket's missing * Disable s3_logging and s3_sync tests This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/2c4575c248776c65d66b06cd60fa09b0dae1cd6f --- plugins/modules/elb_classic_lb_info.py | 60 ++++++++++++++++---------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 3d3d43d4e71..db3fd46ac48 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -161,63 +161,79 @@ def list_elbs(connection, load_balancer_names): def describe_elb(connection, lb): description = camel_dict_to_snake_dict(lb) - name = lb['LoadBalancerName'] - instances = lb.get('Instances', []) - description['tags'] = get_tags(connection, name) - description['instances_inservice'], description['instances_inservice_count'] = lb_instance_health(connection, name, instances, 'InService') - description['instances_outofservice'], description['instances_outofservice_count'] = lb_instance_health(connection, name, instances, 'OutOfService') - description['instances_unknownservice'], description['instances_unknownservice_count'] = lb_instance_health(connection, name, instances, 'Unknown') - description['attributes'] = get_lb_attributes(connection, name) + name = lb["LoadBalancerName"] + instances = lb.get("Instances", []) + description["tags"] = get_tags(connection, name) + description["instances_inservice"], description["instances_inservice_count"] = lb_instance_health( + connection, name, instances, "InService" + ) + description["instances_outofservice"], description["instances_outofservice_count"] = lb_instance_health( + connection, name, instances, "OutOfService" + ) + description["instances_unknownservice"], description["instances_unknownservice_count"] = lb_instance_health( + connection, name, instances, "Unknown" + ) + description["attributes"] = get_lb_attributes(connection, name) return description @AWSRetry.jittered_backoff() def get_all_lb(connection): - paginator = connection.get_paginator('describe_load_balancers') - return paginator.paginate().build_full_result()['LoadBalancerDescriptions'] + paginator = connection.get_paginator("describe_load_balancers") + return paginator.paginate().build_full_result()["LoadBalancerDescriptions"] def get_lb(connection, load_balancer_name): try: - return connection.describe_load_balancers(aws_retry=True, LoadBalancerNames=[load_balancer_name])['LoadBalancerDescriptions'][0] - except is_boto3_error_code('LoadBalancerNotFound'): + return connection.describe_load_balancers(aws_retry=True, LoadBalancerNames=[load_balancer_name])[ + "LoadBalancerDescriptions" + ][0] + except is_boto3_error_code("LoadBalancerNotFound"): return [] def get_lb_attributes(connection, load_balancer_name): - attributes = connection.describe_load_balancer_attributes(aws_retry=True, LoadBalancerName=load_balancer_name).get('LoadBalancerAttributes', {}) + attributes = connection.describe_load_balancer_attributes(aws_retry=True, LoadBalancerName=load_balancer_name).get( + "LoadBalancerAttributes", {} + ) return camel_dict_to_snake_dict(attributes) def get_tags(connection, load_balancer_name): - tags = connection.describe_tags(aws_retry=True, LoadBalancerNames=[load_balancer_name])['TagDescriptions'] + tags = connection.describe_tags(aws_retry=True, LoadBalancerNames=[load_balancer_name])["TagDescriptions"] if not tags: return {} - return boto3_tag_list_to_ansible_dict(tags[0]['Tags']) + return boto3_tag_list_to_ansible_dict(tags[0]["Tags"]) def lb_instance_health(connection, load_balancer_name, instances, state): - instance_states = connection.describe_instance_health(LoadBalancerName=load_balancer_name, Instances=instances).get('InstanceStates', []) - instate = [instance['InstanceId'] for instance in instance_states if instance['State'] == state] + instance_states = connection.describe_instance_health(LoadBalancerName=load_balancer_name, Instances=instances).get( + "InstanceStates", [] + ) + instate = [instance["InstanceId"] for instance in instance_states if instance["State"] == state] return instate, len(instate) def main(): argument_spec = dict( - names=dict(default=[], type='list', elements='str') + names=dict(default=[], type="list", elements="str"), + ) + module = AnsibleAWSModule( + argument_spec=argument_spec, + supports_check_mode=True, ) - module = AnsibleAWSModule(argument_spec=argument_spec, - supports_check_mode=True) - connection = module.client('elb', retry_decorator=AWSRetry.jittered_backoff(retries=MAX_AWS_RETRIES, delay=MAX_AWS_DELAY)) + connection = module.client( + "elb", retry_decorator=AWSRetry.jittered_backoff(retries=MAX_AWS_RETRIES, delay=MAX_AWS_DELAY) + ) try: - elbs = list_elbs(connection, module.params.get('names')) + elbs = list_elbs(connection, module.params.get("names")) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg="Failed to get load balancer information.") module.exit_json(elbs=elbs) -if __name__ == '__main__': +if __name__ == "__main__": main() From b01366e5e8a2d4a94c23e1d0d691bd6525dabeb0 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Thu, 31 Aug 2023 17:58:59 +0200 Subject: [PATCH 21/32] Mass update of docs and tests (credentials/session tokens) (#1921) Mass update of docs and tests (credentials/session tokens) SUMMARY We had a cleanup of credentials/session parameters which included a batch of deprecations and renames. Ensure that all of our tests and docs are using the 'canonical' names ISSUE TYPE Docs Pull Request COMPONENT NAME plugins/modules/batch_compute_environment.py plugins/modules/cloudformation_exports_info.py plugins/modules/ec2_vpc_vpn.py plugins/modules/elasticache.py plugins/modules/elasticache_parameter_group.py plugins/modules/elasticache_snapshot.py plugins/modules/ses_rule_set.py plugins/modules/sts_assume_role.py plugins/modules/sts_session_token.py tests/integration ADDITIONAL INFORMATION See also ansible-collections/amazon.aws#1172 ansible-collections/amazon.aws#1714 Reviewed-by: Alina Buzachis This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/4a5b50e9b9c0d6ca1a1f802f3b03d4f503c16885 --- .../elb_classic_lb_info/tasks/main.yml | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml index e4cd8144b1e..dc099388648 100644 --- a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml +++ b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml @@ -18,10 +18,10 @@ - module_defaults: group/aws: - region: "{{ ec2_region }}" - ec2_access_key: "{{ ec2_access_key }}" - ec2_secret_key: "{{ ec2_secret_key }}" - security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + access_key: "{{ aws_access_key }}" + secret_key: "{{ aws_secret_key }}" + session_token: "{{ security_token | default(omit) }}" block: # ============================================================ @@ -32,8 +32,8 @@ name: "{{ elb_name }}" state: present zones: - - "{{ ec2_region }}a" - - "{{ ec2_region }}b" + - "{{ aws_region }}a" + - "{{ aws_region }}b" listeners: - protocol: http load_balancer_port: 80 @@ -55,8 +55,8 @@ that: - create is changed # We rely on these for the info test, make sure they're what we expect - - '"{{ ec2_region }}a" in create.elb.zones' - - '"{{ ec2_region }}b" in create.elb.zones' + - '"{{ aws_region }}a" in create.elb.zones' + - '"{{ aws_region }}b" in create.elb.zones' - create.elb.health_check.healthy_threshold == 10 - create.elb.health_check.interval == 30 - create.elb.health_check.target == "HTTP:80/index.html" @@ -74,8 +74,8 @@ that: - info.elbs|length == 1 - elb.availability_zones|length == 2 - - '"{{ ec2_region }}a" in elb.availability_zones' - - '"{{ ec2_region }}b" in elb.availability_zones' + - '"{{ aws_region }}a" in elb.availability_zones' + - '"{{ aws_region }}b" in elb.availability_zones' - elb.health_check.healthy_threshold == 10 - elb.health_check.interval == 30 - elb.health_check.target == "HTTP:80/index.html" @@ -115,7 +115,7 @@ name: "{{ elb_name }}" state: present zones: - - "{{ ec2_region }}c" + - "{{ aws_region }}c" listeners: - protocol: http load_balancer_port: 80 @@ -134,7 +134,7 @@ - assert: that: - update_az is changed - - update_az.elb.zones[0] == "{{ ec2_region }}c" + - update_az.elb.zones[0] == "{{ aws_region }}c" - name: Get ELB info after changing AZ's elb_classic_lb_info: @@ -144,7 +144,7 @@ - assert: that: - elb.availability_zones|length == 1 - - '"{{ ec2_region }}c" in elb.availability_zones[0]' + - '"{{ aws_region }}c" in elb.availability_zones[0]' vars: elb: "{{ info.elbs[0] }}" @@ -157,9 +157,9 @@ name: "{{ elb_name }}" state: present zones: - - "{{ ec2_region }}a" - - "{{ ec2_region }}b" - - "{{ ec2_region }}c" + - "{{ aws_region }}a" + - "{{ aws_region }}b" + - "{{ aws_region }}c" listeners: - protocol: http load_balancer_port: 80 @@ -170,9 +170,9 @@ - assert: that: - update_az is changed - - '"{{ ec2_region }}a" in update_az.elb.zones' - - '"{{ ec2_region }}b" in update_az.elb.zones' - - '"{{ ec2_region }}c" in update_az.elb.zones' + - '"{{ aws_region }}a" in update_az.elb.zones' + - '"{{ aws_region }}b" in update_az.elb.zones' + - '"{{ aws_region }}c" in update_az.elb.zones' - name: Get ELB info after updating AZ's elb_classic_lb_info: @@ -182,9 +182,9 @@ - assert: that: - elb.availability_zones|length == 3 - - '"{{ ec2_region }}a" in elb.availability_zones' - - '"{{ ec2_region }}b" in elb.availability_zones' - - '"{{ ec2_region }}c" in elb.availability_zones' + - '"{{ aws_region }}a" in elb.availability_zones' + - '"{{ aws_region }}b" in elb.availability_zones' + - '"{{ aws_region }}c" in elb.availability_zones' vars: elb: "{{ info.elbs[0] }}" @@ -197,9 +197,9 @@ name: "{{ elb_name }}" state: present zones: - - "{{ ec2_region }}a" - - "{{ ec2_region }}b" - - "{{ ec2_region }}c" + - "{{ aws_region }}a" + - "{{ aws_region }}b" + - "{{ aws_region }}c" listeners: - protocol: http load_balancer_port: 80 @@ -235,9 +235,9 @@ name: "{{ elb_name }}" state: present zones: - - "{{ ec2_region }}a" - - "{{ ec2_region }}b" - - "{{ ec2_region }}c" + - "{{ aws_region }}a" + - "{{ aws_region }}b" + - "{{ aws_region }}c" listeners: - protocol: http load_balancer_port: 8081 From c1caa15a9e26796ac7ca78ca0ecbf3b5bbd5e6f2 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Tue, 17 Oct 2023 21:27:02 +0200 Subject: [PATCH 22/32] Apply isort and flynt (#1962) SUMMARY Apply isort - see also ansible-collections/amazon.aws#1771 Apply flynt - see also ansible-collections/amazon.aws#1802 ISSUE TYPE Feature Pull Request COMPONENT NAME ADDITIONAL INFORMATION This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/c0117b5466958bd0f8b5fc620306adde1422a62d --- plugins/modules/elb_classic_lb_info.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index db3fd46ac48..8ac3b1f1c6a 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -139,7 +139,6 @@ from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule - MAX_AWS_RETRIES = 5 MAX_AWS_DELAY = 5 From 51157f461c640fb03405d45a5db73a4bd634cb3e Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Fri, 1 Dec 2023 13:50:37 +0100 Subject: [PATCH 23/32] fix unsafe asserts (#2013) fix unsafe asserts SUMMARY Closes #2012 ISSUE TYPE Bugfix Pull Request COMPONENT NAME integrationtests Reviewed-by: Mark Chappell Reviewed-by: Alina Buzachis This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/4bdcecda3d37e1ccd4d568ec641b59d0a745bbca --- .../elb_classic_lb_info/tasks/main.yml | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml index dc099388648..b09e8807269 100644 --- a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml +++ b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml @@ -55,8 +55,8 @@ that: - create is changed # We rely on these for the info test, make sure they're what we expect - - '"{{ aws_region }}a" in create.elb.zones' - - '"{{ aws_region }}b" in create.elb.zones' + - aws_region ~ 'a' in create.elb.zones + - aws_region ~ 'b' in create.elb.zones - create.elb.health_check.healthy_threshold == 10 - create.elb.health_check.interval == 30 - create.elb.health_check.target == "HTTP:80/index.html" @@ -74,8 +74,8 @@ that: - info.elbs|length == 1 - elb.availability_zones|length == 2 - - '"{{ aws_region }}a" in elb.availability_zones' - - '"{{ aws_region }}b" in elb.availability_zones' + - aws_region ~ 'a' in elb.availability_zones + - aws_region ~ 'b' in elb.availability_zones - elb.health_check.healthy_threshold == 10 - elb.health_check.interval == 30 - elb.health_check.target == "HTTP:80/index.html" @@ -134,7 +134,7 @@ - assert: that: - update_az is changed - - update_az.elb.zones[0] == "{{ aws_region }}c" + - update_az.elb.zones[0] == aws_region ~ 'c' - name: Get ELB info after changing AZ's elb_classic_lb_info: @@ -144,7 +144,7 @@ - assert: that: - elb.availability_zones|length == 1 - - '"{{ aws_region }}c" in elb.availability_zones[0]' + - aws_region ~ 'c' in elb.availability_zones[0] vars: elb: "{{ info.elbs[0] }}" @@ -170,9 +170,9 @@ - assert: that: - update_az is changed - - '"{{ aws_region }}a" in update_az.elb.zones' - - '"{{ aws_region }}b" in update_az.elb.zones' - - '"{{ aws_region }}c" in update_az.elb.zones' + - aws_region ~ 'a' in update_az.elb.zones + - aws_region ~ 'b' in update_az.elb.zones + - aws_region ~ 'c' in update_az.elb.zones - name: Get ELB info after updating AZ's elb_classic_lb_info: @@ -182,9 +182,9 @@ - assert: that: - elb.availability_zones|length == 3 - - '"{{ aws_region }}a" in elb.availability_zones' - - '"{{ aws_region }}b" in elb.availability_zones' - - '"{{ aws_region }}c" in elb.availability_zones' + - aws_region ~ 'a' in elb.availability_zones + - aws_region ~ 'b' in elb.availability_zones + - aws_region ~ 'c' in elb.availability_zones vars: elb: "{{ info.elbs[0] }}" From 2a5dfb4f537d00f888a268394a188a928203312a Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 5 Jan 2024 18:42:41 +0100 Subject: [PATCH 24/32] ansible-lint (documentation) cleanup for plugins/ (#2036) ansible-lint (documentation) cleanup for plugins/ SUMMARY Fixes an array of ansible-lint failures in plugins/ Adds ansible-lint plugins/ to tox -m lint ISSUE TYPE Docs Pull Request COMPONENT NAME plugins/ ADDITIONAL INFORMATION docs changes only (no changelog fragment needed) Reviewed-by: Alina Buzachis This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/6dd4a00b8c18fe3499bad04f90c8ac7832ade8bb --- plugins/modules/elb_classic_lb_info.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 8ac3b1f1c6a..5329e5b81db 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -50,14 +50,13 @@ # Gather information about a set of ELBs - community.aws.elb_classic_lb_info: names: - - frontend-prod-elb - - backend-prod-elb + - frontend-prod-elb + - backend-prod-elb register: elb_info - ansible.builtin.debug: msg: "{{ item.dns_name }}" loop: "{{ elb_info.elbs }}" - """ RETURN = r""" From 72b87d834fb8fa24d5b2ce2f1eacaae190bb04ea Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 25 Sep 2024 18:42:42 -0700 Subject: [PATCH 25/32] elb_classic_lb_info: Refactor elb_classic_lb_info module (#2139) SUMMARY Added type hints and function descriptions. Updated return block of the module. ISSUE TYPE Docs Pull Request COMPONENT NAME elb_classic_lb_info ADDITIONAL INFORMATION Reviewed-by: Markus Bergholz Reviewed-by: Alina Buzachis Reviewed-by: Mandar Kulkarni Reviewed-by: Mark Chappell Reviewed-by: GomathiselviS This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/2ad8a8ff5b620b6bd2dc57fa9d695c7622e09c11 --- plugins/modules/elb_classic_lb_info.py | 443 ++++++++++++++++++++----- 1 file changed, 361 insertions(+), 82 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 5329e5b81db..2115ca70f1e 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -8,9 +8,9 @@ --- module: elb_classic_lb_info version_added: 1.0.0 -short_description: Gather information about EC2 Elastic Load Balancers in AWS +short_description: Gather information about EC2 Classic Elastic Load Balancers in AWS description: - - Gather information about EC2 Elastic Load Balancers in AWS + - Gather information about EC2 Classic Elastic Load Balancers in AWS. author: - "Michael Schultz (@mjschultz)" - "Fernando Jose Pando (@nand0p)" @@ -29,26 +29,26 @@ EXAMPLES = r""" # Note: These examples do not set authentication details, see the AWS Guide for details. -# Output format tries to match amazon.aws.ec2_elb_lb module input parameters +# Output format tries to match amazon.aws.elb_classic_lb module input parameters -# Gather information about all ELBs -- community.aws.elb_classic_lb_info: +- name: Gather information about all ELBs + community.aws.elb_classic_lb_info: register: elb_info - ansible.builtin.debug: msg: "{{ item.dns_name }}" loop: "{{ elb_info.elbs }}" -# Gather information about a particular ELB -- community.aws.elb_classic_lb_info: +- name: Gather information about a particular ELB + community.aws.elb_classic_lb_info: names: frontend-prod-elb register: elb_info - ansible.builtin.debug: msg: "{{ elb_info.elbs.0.dns_name }}" -# Gather information about a set of ELBs -- community.aws.elb_classic_lb_info: +- name: Gather information about a set of ELBs + community.aws.elb_classic_lb_info: names: - frontend-prod-elb - backend-prod-elb @@ -61,70 +61,282 @@ RETURN = r""" elbs: - description: a list of load balancers + description: A list of load balancers. returned: always type: list - sample: - elbs: - - attributes: - access_log: - enabled: false - connection_draining: - enabled: true - timeout: 300 - connection_settings: - idle_timeout: 60 - cross_zone_load_balancing: - enabled: true - availability_zones: - - "us-east-1a" - - "us-east-1b" - - "us-east-1c" - - "us-east-1d" - - "us-east-1e" - backend_server_description: [] - canonical_hosted_zone_name: test-lb-XXXXXXXXXXXX.us-east-1.elb.amazonaws.com - canonical_hosted_zone_name_id: XXXXXXXXXXXXXX - created_time: '2017-08-23T18:25:03.280000+00:00' - dns_name: test-lb-XXXXXXXXXXXX.us-east-1.elb.amazonaws.com - health_check: - healthy_threshold: 10 - interval: 30 - target: HTTP:80/index.html - timeout: 5 - unhealthy_threshold: 2 - instances: [] - instances_inservice: [] - instances_inservice_count: 0 - instances_outofservice: [] - instances_outofservice_count: 0 - instances_unknownservice: [] - instances_unknownservice_count: 0 - listener_descriptions: - - listener: - instance_port: 80 - instance_protocol: HTTP - load_balancer_port: 80 - protocol: HTTP - policy_names: [] - load_balancer_name: test-lb - policies: - app_cookie_stickiness_policies: [] - lb_cookie_stickiness_policies: [] - other_policies: [] - scheme: internet-facing - security_groups: - - sg-29d13055 - source_security_group: - group_name: default - owner_alias: XXXXXXXXXXXX - subnets: - - subnet-XXXXXXXX - - subnet-XXXXXXXX - tags: {} - vpc_id: vpc-c248fda4 + elements: dict + contains: + attributes: + description: Information about the load balancer attributes. + returned: always + type: dict + contains: + access_log: + description: Information on whether access logs are enabled or not. + type: dict + sample: { + "enabled": false + } + additional_attributes: + description: Information about additional load balancer attributes. + type: list + elements: dict + sample: [ + { + "key": "elb.http.desyncmitigationmode", + "value": "defensive" + } + ] + connection_draining: + description: + - Information on connection draining configuration of elastic load balancer. + type: dict + sample: { + "enabled": true, + "timeout": 300 + } + contains: + enabled: + description: Whether connection draining is enabled. + type: bool + returned: always + timeout: + description: The maximum time, in seconds, to keep the existing connections open before deregistering the instances. + type: int + returned: always + connection_settings: + description: Information on connection settings. + type: dict + sample: { + "idle_timeout": 60 + } + cross_zone_load_balancing: + description: Information on whether cross zone load balancing is enabled or not. + type: dict + sample: { + "enabled": true + } + availability_zones: + description: The Availability Zones for the load balancer. + type: list + elements: str + returned: always + sample: [ + "us-west-2a" + ] + backend_server_descriptions: + description: Information about your EC2 instances. + type: list + elements: dict + returned: always + sample: [ + { + instance_port: 8085, + policy_names: [ + 'MyPolicy1', + ] + }, + ] + canonical_hosted_zone_name: + description: The DNS name of the load balancer. + type: str + returned: always + sample: "test-123456789.us-west-2.elb.amazonaws.com" + canonical_hosted_zone_name_id: + description: The ID of the Amazon Route 53 hosted zone for the load balancer. + type: str + returned: always + sample: "Z1Z1ZZ5HABSF5" + created_time: + description: The date and time the load balancer was created. + type: str + returned: always + sample: "2024-09-04T17:52:22.270000+00:00" + dns_name: + description: The DNS name of the load balancer. + type: str + returned: "always" + sample: "test-123456789.us-west-2.elb.amazonaws.com" + health_check: + description: Information about the health checks conducted on the load balancer. + type: dict + returned: always + sample: { + "healthy_threshold": 10, + "interval": 5, + "target": "HTTP:80/index.html", + "timeout": 2, + "unhealthy_threshold": 2 + } + contains: + healthy_threshold: + description: The number of consecutive health checks successes required before moving the instance to the Healthy state. + type: int + returned: always + interval: + description: The approximate interval, in seconds, between health checks of an individual instance. + type: int + returned: always + target: + description: The instance being checked. The protocol is either TCP, HTTP, HTTPS, or SSL. The range of valid ports is one (1) through 65535. + type: str + returned: always + timeout: + description: The amount of time, in seconds, during which no response means a failed health check. + type: int + returned: always + unhealthy_threshold: + description: The number of consecutive health checks successes required before moving the instance to the Unhealthy state. + type: int + returned: always + instances: + description: The IDs of the instances for the load balancer. + type: list + elements: dict + returned: always + sample: [ + { + "instance_id": "i-11d1f111ea111111b" + } + ] + instances_inservice: + description: Information about instances for load balancer in state "InService". + type: list + returned: always + sample: [ + "i-11d1f111ea111111b" + ] + instances_inservice_count: + description: Total number of instances for load balancer with state "InService". + type: int + returned: always + sample: 1 + instances_outofservice: + description: Information about instances for load balancer in state "OutOfService". + type: list + returned: always + sample: [ + "i-11d1f111ea111111b" + ] + instances_outofservice_count: + description: Total number of instances for load balancer with state "OutOfService". + type: int + returned: always + sample: 0 + instances_unknownservice: + description: Information about instances for load balancer in state "Unknown". + type: list + returned: always + sample: [ + "i-11d1f111ea111111b" + ] + instances_unknownservice_count: + description: Total number of instances for load balancer with state "Unknown". + type: int + returned: always + sample: 1 + listener_descriptions: + description: Information about the listeners for the load balancer. + type: list + elements: dict + returned: always + sample: [ + { + "listener": { + "instance_port": 80, + "instance_protocol": "HTTP", + "load_balancer_port": 80, + "protocol": "HTTP" + }, + "policy_names": [] + } + ] + load_balancer_name: + description: The name of the elastic load balancer. + type: str + returned: always + sample: "MyLoadBalancer" + policies: + description: Information about the policies defined for the load balancer. + type: dict + returned: always + sample: { + "app_cookie_stickiness_policies": [], + "lb_cookie_stickiness_policies": [], + "other_policies": [] + } + contains: + app_cookie_stickiness_policies: + description: The stickiness policies created using CreateAppCookieStickinessPolicy. + type: list + returned: always + lb_cookie_stickiness_policies: + description: The stickiness policies created using CreateLBCookieStickinessPolicy. + type: list + returned: always + other_policies: + description: The policies other than the stickiness policies. + type: list + returned: always + scheme: + description: The type of load balancer. + type: str + returned: always + sample: "internet-facing" + security_groups: + description: The security groups for the load balancer. + type: list + returned: always + sample: [ + "sg-111111af1111cb111" + ] + source_security_group: + description: + - The security group for the load balancer, + which are used as part of inbound rules for registered instances. + type: dict + returned: always + sample: { + "group_name": "default", + "owner_alias": "721111111111" + } + contains: + group_name: + description: The name of the security group. + type: str + returned: always + owner_alias: + description: The owner of the security group. + type: str + returned: always + subnets: + description: The IDs of the subnets for the load balancer. + type: list + returned: always + sample: [ + "subnet-111111af1111cb111" + ] + tags: + description: The tags associated with a load balancer. + type: dict + returned: always + sample: { + "Env": "Dev", + "Owner": "Dev001" + } + vpc_id: + description: The ID of the VPC for the load balancer. + type: str + returned: always + sample: "vpc-0cc28c9e20d111111" """ +from typing import Any +from typing import Dict +from typing import List +from typing import Tuple +from typing import Union + try: import botocore except ImportError: @@ -133,16 +345,22 @@ from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict -from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule -MAX_AWS_RETRIES = 5 -MAX_AWS_DELAY = 5 +def list_elbs(connection: Any, load_balancer_names: List[str]) -> List[Dict]: + """ + List Elastic Load Balancers (ELBs) and their detailed information. + Parameters: + connection (boto3.client): The Boto3 ELB client object. + load_balancer_names (List[str]): List of ELB names to gather information about. -def list_elbs(connection, load_balancer_names): + Returns: + A list of dictionaries where each dictionary contains informtion about one ELB. + """ results = [] if not load_balancer_names: @@ -157,7 +375,17 @@ def list_elbs(connection, load_balancer_names): return results -def describe_elb(connection, lb): +def describe_elb(connection: Any, lb: Dict[str, Any]) -> Dict[str, Any]: + """ + Describes an Elastic Load Balancer (ELB). + + Parameters: + connection (boto3.client): The Boto3 ELB client object. + lb (Dict): Dictionary containing ELB . + + Returns: + A dictionary with detailed information of the ELB. + """ description = camel_dict_to_snake_dict(lb) name = lb["LoadBalancerName"] instances = lb.get("Instances", []) @@ -176,12 +404,31 @@ def describe_elb(connection, lb): @AWSRetry.jittered_backoff() -def get_all_lb(connection): +def get_all_lb(connection: Any) -> List: + """ + Get paginated result for information of all Elastic Load Balancers. + + Parameters: + connection (boto3.client): The Boto3 ELB client object. + + Returns: + A list of dictionaries containing descriptions of all ELBs. + """ paginator = connection.get_paginator("describe_load_balancers") return paginator.paginate().build_full_result()["LoadBalancerDescriptions"] -def get_lb(connection, load_balancer_name): +def get_lb(connection: Any, load_balancer_name: str) -> Union[Dict[str, Any], List]: + """ + Describes a specific Elastic Load Balancer (ELB) by name. + + Parameters: + connection (boto3.client): The Boto3 ELB client object. + load_balancer_name (str): Name of the ELB to gather information about. + + Returns: + A dictionary with detailed information of the specified ELB. + """ try: return connection.describe_load_balancers(aws_retry=True, LoadBalancerNames=[load_balancer_name])[ "LoadBalancerDescriptions" @@ -190,21 +437,55 @@ def get_lb(connection, load_balancer_name): return [] -def get_lb_attributes(connection, load_balancer_name): +def get_lb_attributes(connection: Any, load_balancer_name: str) -> Dict[str, Any]: + """ + Retrieves attributes of specific Elastic Load Balancer (ELB) by name. + + Parameters: + connection (boto3.client): The Boto3 ELB client object. + load_balancer_name (str): Name of the ELB to gather information about. + + Returns: + A dictionary with detailed information of the attributes of specified ELB. + """ attributes = connection.describe_load_balancer_attributes(aws_retry=True, LoadBalancerName=load_balancer_name).get( "LoadBalancerAttributes", {} ) return camel_dict_to_snake_dict(attributes) -def get_tags(connection, load_balancer_name): +def get_tags(connection: Any, load_balancer_name: str) -> Dict[str, Any]: + """ + Retrieves tags of specific Elastic Load Balancer (ELB) by name. + + Parameters: + connection (boto3.client): The Boto3 ELB client object. + load_balancer_name (str): Name of the ELB to gather information about. + + Returns: + A dictionary of tags associated with the specified ELB. + """ tags = connection.describe_tags(aws_retry=True, LoadBalancerNames=[load_balancer_name])["TagDescriptions"] if not tags: return {} return boto3_tag_list_to_ansible_dict(tags[0]["Tags"]) -def lb_instance_health(connection, load_balancer_name, instances, state): +def lb_instance_health( + connection: Any, load_balancer_name: str, instances: List[Dict[str, Any]], state: str +) -> Tuple[List[str], int]: + """ + Describes the health status of instances associated with a specific Elastic Load Balancer (ELB). + + Parameters: + connection (Any): The Boto3 client object for ELB. + load_balancer_name (str): The name of the ELB. + instances (List[Dict]): List of dictionaries containing instances associated with the ELB. + state (str): The health state to filter by (e.g., "InService", "OutOfService", "Unknown"). + + Returns: + Tuple[List, int]: A tuple containing a list of instance IDs matching state and the count of matching instances. + """ instance_states = connection.describe_instance_health(LoadBalancerName=load_balancer_name, Instances=instances).get( "InstanceStates", [] ) @@ -221,9 +502,7 @@ def main(): supports_check_mode=True, ) - connection = module.client( - "elb", retry_decorator=AWSRetry.jittered_backoff(retries=MAX_AWS_RETRIES, delay=MAX_AWS_DELAY) - ) + connection = module.client("elb", retry_decorator=AWSRetry.jittered_backoff(retries=5, delay=5)) try: elbs = list_elbs(connection, module.params.get("names")) From 83da8621229a83de90c073c514d3f49ad7ee10e5 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 30 Sep 2024 12:41:16 -0700 Subject: [PATCH 26/32] Update runtime --- meta/runtime.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/meta/runtime.yml b/meta/runtime.yml index 94614615f1e..0b20328f0be 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -71,6 +71,7 @@ action_groups: - elb_application_lb - elb_application_lb_info - elb_classic_lb + - elb_classic_lb_info - execute_lambda - iam_access_key - iam_access_key_info @@ -162,14 +163,14 @@ plugin_routing: rds_param_group: redirect: amazon.aws.rds_instance_param_group deprecation: - removal_version: 10.0.0 - warning_text: >- - rds_param_group has been renamed to rds_instance_param_group. - Please update your tasks. + removal_version: 10.0.0 + warning_text: >- + rds_param_group has been renamed to rds_instance_param_group. + Please update your tasks. lookup: aws_ssm: # Deprecation for this alias should not *start* prior to 2024-09-01 redirect: amazon.aws.ssm_parameter aws_secret: # Deprecation for this alias should not *start* prior to 2024-09-01 - redirect: amazon.aws.secretsmanager_secret + redirect: amazon.aws.secretsmanager_secret \ No newline at end of file From a8f444e6a5f9c2893ddaebd7cfee2c6268d8777e Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 30 Sep 2024 12:41:16 -0700 Subject: [PATCH 27/32] Update FQDN --- plugins/modules/elb_classic_lb_info.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 2115ca70f1e..29950af068f 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -32,7 +32,7 @@ # Output format tries to match amazon.aws.elb_classic_lb module input parameters - name: Gather information about all ELBs - community.aws.elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: register: elb_info - ansible.builtin.debug: @@ -40,7 +40,7 @@ loop: "{{ elb_info.elbs }}" - name: Gather information about a particular ELB - community.aws.elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: names: frontend-prod-elb register: elb_info @@ -48,7 +48,7 @@ msg: "{{ elb_info.elbs.0.dns_name }}" - name: Gather information about a set of ELBs - community.aws.elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: names: - frontend-prod-elb - backend-prod-elb From adf7d3e19717fd2c70439f8f16aec9cb6db0e4aa Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 30 Sep 2024 12:41:16 -0700 Subject: [PATCH 28/32] Remove collection reference inside the tests --- .../elb_classic_lb_info/defaults/main.yml | 3 +- .../elb_classic_lb_info/tasks/main.yml | 466 +++++++++--------- 2 files changed, 237 insertions(+), 232 deletions(-) diff --git a/tests/integration/targets/elb_classic_lb_info/defaults/main.yml b/tests/integration/targets/elb_classic_lb_info/defaults/main.yml index bd059e26ea7..7279a8194da 100644 --- a/tests/integration/targets/elb_classic_lb_info/defaults/main.yml +++ b/tests/integration/targets/elb_classic_lb_info/defaults/main.yml @@ -1,3 +1,2 @@ ---- # defaults file for test_ec2_eip -elb_name: 'ansible-test-{{ tiny_prefix }}-ecli' +elb_name: ansible-test-{{ tiny_prefix }}-ecli diff --git a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml index b09e8807269..49bfa7e31fd 100644 --- a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml +++ b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml @@ -1,4 +1,3 @@ ---- # __Test Info__ # Create a self signed cert and upload it to AWS # http://www.akadia.com/services/ssh_test_certificate.html @@ -18,74 +17,77 @@ - module_defaults: group/aws: - region: "{{ aws_region }}" - access_key: "{{ aws_access_key }}" - secret_key: "{{ aws_secret_key }}" - session_token: "{{ security_token | default(omit) }}" + region: '{{ aws_region }}' + access_key: '{{ aws_access_key }}' + secret_key: '{{ aws_secret_key }}' + session_token: '{{ security_token | default(omit) }}' block: # ============================================================ # create test elb with listeners, certificate, and health check - - name: Create ELB - elb_classic_lb: - name: "{{ elb_name }}" - state: present - zones: - - "{{ aws_region }}a" - - "{{ aws_region }}b" - listeners: - - protocol: http - load_balancer_port: 80 - instance_port: 80 - - protocol: http - load_balancer_port: 8080 - instance_port: 8080 - health_check: - ping_protocol: http - ping_port: 80 - ping_path: "/index.html" - response_timeout: 5 - interval: 30 - unhealthy_threshold: 2 - healthy_threshold: 10 - register: create - - - assert: - that: - - create is changed + - name: Create ELB + elb_classic_lb: + name: '{{ elb_name }}' + state: present + zones: + - '{{ aws_region }}a' + - '{{ aws_region }}b' + listeners: + - protocol: http + load_balancer_port: 80 + instance_port: 80 + - protocol: http + load_balancer_port: 8080 + instance_port: 8080 + health_check: + ping_protocol: http + ping_port: 80 + ping_path: /index.html + response_timeout: 5 + interval: 30 + unhealthy_threshold: 2 + healthy_threshold: 10 + register: create + + - assert: + that: + - create is changed # We rely on these for the info test, make sure they're what we expect - - aws_region ~ 'a' in create.elb.zones - - aws_region ~ 'b' in create.elb.zones - - create.elb.health_check.healthy_threshold == 10 - - create.elb.health_check.interval == 30 - - create.elb.health_check.target == "HTTP:80/index.html" - - create.elb.health_check.timeout == 5 - - create.elb.health_check.unhealthy_threshold == 2 - - '[80, 80, "HTTP", "HTTP"] in create.elb.listeners' - - '[8080, 8080, "HTTP", "HTTP"] in create.elb.listeners' - - - name: Get ELB info - elb_classic_lb_info: - names: "{{ elb_name }}" - register: info - - - assert: - that: - - info.elbs|length == 1 - - elb.availability_zones|length == 2 - - aws_region ~ 'a' in elb.availability_zones - - aws_region ~ 'b' in elb.availability_zones - - elb.health_check.healthy_threshold == 10 - - elb.health_check.interval == 30 - - elb.health_check.target == "HTTP:80/index.html" - - elb.health_check.timeout == 5 - - elb.health_check.unhealthy_threshold == 2 - - '{"instance_port": 80, "instance_protocol": "HTTP", "load_balancer_port": 80, "protocol": "HTTP"} == listeners[0]' - - '{"instance_port": 8080, "instance_protocol": "HTTP", "load_balancer_port": 8080, "protocol": "HTTP"} == listeners[1]' - vars: - elb: "{{ info.elbs[0] }}" - listeners: "{{ elb.listener_descriptions|map(attribute='listener')|sort(attribute='load_balancer_port') }}" + - aws_region ~ 'a' in create.elb.zones + - aws_region ~ 'b' in create.elb.zones + - create.elb.health_check.healthy_threshold == 10 + - create.elb.health_check.interval == 30 + - create.elb.health_check.target == "HTTP:80/index.html" + - create.elb.health_check.timeout == 5 + - create.elb.health_check.unhealthy_threshold == 2 + - '[80, 80, "HTTP", "HTTP"] in create.elb.listeners' + - '[8080, 8080, "HTTP", "HTTP"] in create.elb.listeners' + + - name: Get ELB info + elb_classic_lb_info: + names: '{{ elb_name }}' + register: info + + - assert: + that: + - info.elbs|length == 1 + - elb.availability_zones|length == 2 + - aws_region ~ 'a' in elb.availability_zones + - aws_region ~ 'b' in elb.availability_zones + - elb.health_check.healthy_threshold == 10 + - elb.health_check.interval == 30 + - elb.health_check.target == "HTTP:80/index.html" + - elb.health_check.timeout == 5 + - elb.health_check.unhealthy_threshold == 2 + - '{"instance_port": 80, "instance_protocol": "HTTP", "load_balancer_port": + 80, "protocol": "HTTP"} == listeners[0]' + - '{"instance_port": 8080, "instance_protocol": "HTTP", "load_balancer_port": + 8080, "protocol": "HTTP"} == listeners[1]' + vars: + elb: '{{ info.elbs[0] }}' + listeners: "{{ elb.listener_descriptions|map(attribute='listener')|sort(attribute='load_balancer_port') + }}" # ============================================================ @@ -110,202 +112,206 @@ # Change AZ's - - name: Change AZ's - elb_classic_lb: - name: "{{ elb_name }}" - state: present - zones: - - "{{ aws_region }}c" - listeners: - - protocol: http - load_balancer_port: 80 - instance_port: 80 - purge_zones: yes - health_check: - ping_protocol: http - ping_port: 80 - ping_path: "/index.html" - response_timeout: 5 - interval: 30 - unhealthy_threshold: 2 - healthy_threshold: 10 - register: update_az - - - assert: - that: - - update_az is changed - - update_az.elb.zones[0] == aws_region ~ 'c' - - - name: Get ELB info after changing AZ's - elb_classic_lb_info: - names: "{{ elb_name }}" - register: info - - - assert: - that: - - elb.availability_zones|length == 1 - - aws_region ~ 'c' in elb.availability_zones[0] - vars: - elb: "{{ info.elbs[0] }}" + - name: Change AZ's + elb_classic_lb: + name: '{{ elb_name }}' + state: present + zones: + - '{{ aws_region }}c' + listeners: + - protocol: http + load_balancer_port: 80 + instance_port: 80 + purge_zones: yes + health_check: + ping_protocol: http + ping_port: 80 + ping_path: /index.html + response_timeout: 5 + interval: 30 + unhealthy_threshold: 2 + healthy_threshold: 10 + register: update_az + + - assert: + that: + - update_az is changed + - update_az.elb.zones[0] == aws_region ~ 'c' + + - name: Get ELB info after changing AZ's + elb_classic_lb_info: + names: '{{ elb_name }}' + register: info + + - assert: + that: + - elb.availability_zones|length == 1 + - aws_region ~ 'c' in elb.availability_zones[0] + vars: + elb: '{{ info.elbs[0] }}' # ============================================================ # Update AZ's - - name: Update AZ's - elb_classic_lb: - name: "{{ elb_name }}" - state: present - zones: - - "{{ aws_region }}a" - - "{{ aws_region }}b" - - "{{ aws_region }}c" - listeners: - - protocol: http - load_balancer_port: 80 - instance_port: 80 - purge_zones: yes - register: update_az - - - assert: - that: - - update_az is changed - - aws_region ~ 'a' in update_az.elb.zones - - aws_region ~ 'b' in update_az.elb.zones - - aws_region ~ 'c' in update_az.elb.zones - - - name: Get ELB info after updating AZ's - elb_classic_lb_info: - names: "{{ elb_name }}" - register: info - - - assert: - that: - - elb.availability_zones|length == 3 - - aws_region ~ 'a' in elb.availability_zones - - aws_region ~ 'b' in elb.availability_zones - - aws_region ~ 'c' in elb.availability_zones - vars: - elb: "{{ info.elbs[0] }}" + - name: Update AZ's + elb_classic_lb: + name: '{{ elb_name }}' + state: present + zones: + - '{{ aws_region }}a' + - '{{ aws_region }}b' + - '{{ aws_region }}c' + listeners: + - protocol: http + load_balancer_port: 80 + instance_port: 80 + purge_zones: yes + register: update_az + + - assert: + that: + - update_az is changed + - aws_region ~ 'a' in update_az.elb.zones + - aws_region ~ 'b' in update_az.elb.zones + - aws_region ~ 'c' in update_az.elb.zones + + - name: Get ELB info after updating AZ's + elb_classic_lb_info: + names: '{{ elb_name }}' + register: info + + - assert: + that: + - elb.availability_zones|length == 3 + - aws_region ~ 'a' in elb.availability_zones + - aws_region ~ 'b' in elb.availability_zones + - aws_region ~ 'c' in elb.availability_zones + vars: + elb: '{{ info.elbs[0] }}' # ============================================================ # Purge Listeners - - name: Purge Listeners - elb_classic_lb: - name: "{{ elb_name }}" - state: present - zones: - - "{{ aws_region }}a" - - "{{ aws_region }}b" - - "{{ aws_region }}c" - listeners: - - protocol: http - load_balancer_port: 80 - instance_port: 81 - purge_listeners: yes - register: purge_listeners - - - assert: - that: - - purge_listeners is changed - - '[80, 81, "HTTP", "HTTP"] in purge_listeners.elb.listeners' - - purge_listeners.elb.listeners|length == 1 - - - name: Get ELB info after purging listeners - elb_classic_lb_info: - names: "{{ elb_name }}" - register: info - - - assert: - that: - - elb.listener_descriptions|length == 1 - - '{"instance_port": 81, "instance_protocol": "HTTP", "load_balancer_port": 80, "protocol": "HTTP"} == elb.listener_descriptions[0].listener' - vars: - elb: "{{ info.elbs[0] }}" + - name: Purge Listeners + elb_classic_lb: + name: '{{ elb_name }}' + state: present + zones: + - '{{ aws_region }}a' + - '{{ aws_region }}b' + - '{{ aws_region }}c' + listeners: + - protocol: http + load_balancer_port: 80 + instance_port: 81 + purge_listeners: yes + register: purge_listeners + + - assert: + that: + - purge_listeners is changed + - '[80, 81, "HTTP", "HTTP"] in purge_listeners.elb.listeners' + - purge_listeners.elb.listeners|length == 1 + + - name: Get ELB info after purging listeners + elb_classic_lb_info: + names: '{{ elb_name }}' + register: info + + - assert: + that: + - elb.listener_descriptions|length == 1 + - '{"instance_port": 81, "instance_protocol": "HTTP", "load_balancer_port": + 80, "protocol": "HTTP"} == elb.listener_descriptions[0].listener' + vars: + elb: '{{ info.elbs[0] }}' # ============================================================ # add Listeners - - name: Add Listeners - elb_classic_lb: - name: "{{ elb_name }}" - state: present - zones: - - "{{ aws_region }}a" - - "{{ aws_region }}b" - - "{{ aws_region }}c" - listeners: - - protocol: http - load_balancer_port: 8081 - instance_port: 8081 - purge_listeners: no - register: update_listeners - - - assert: - that: - - update_listeners is changed - - '[80, 81, "HTTP", "HTTP"] in update_listeners.elb.listeners' - - '[8081, 8081, "HTTP", "HTTP"] in update_listeners.elb.listeners' - - update_listeners.elb.listeners|length == 2 - - - name: Get ELB info after adding listeners - elb_classic_lb_info: - names: "{{ elb_name }}" - register: info - - - assert: - that: - - elb.listener_descriptions|length == 2 - - '{"instance_port": 81, "instance_protocol": "HTTP", "load_balancer_port": 80, "protocol": "HTTP"} == listeners[0]' - - '{"instance_port": 8081, "instance_protocol": "HTTP", "load_balancer_port": 8081, "protocol": "HTTP"} == listeners[1]' - vars: - elb: "{{ info.elbs[0] }}" - listeners: "{{ elb.listener_descriptions|map(attribute='listener')|sort(attribute='load_balancer_port') }}" + - name: Add Listeners + elb_classic_lb: + name: '{{ elb_name }}' + state: present + zones: + - '{{ aws_region }}a' + - '{{ aws_region }}b' + - '{{ aws_region }}c' + listeners: + - protocol: http + load_balancer_port: 8081 + instance_port: 8081 + purge_listeners: no + register: update_listeners + + - assert: + that: + - update_listeners is changed + - '[80, 81, "HTTP", "HTTP"] in update_listeners.elb.listeners' + - '[8081, 8081, "HTTP", "HTTP"] in update_listeners.elb.listeners' + - update_listeners.elb.listeners|length == 2 + + - name: Get ELB info after adding listeners + elb_classic_lb_info: + names: '{{ elb_name }}' + register: info + + - assert: + that: + - elb.listener_descriptions|length == 2 + - '{"instance_port": 81, "instance_protocol": "HTTP", "load_balancer_port": + 80, "protocol": "HTTP"} == listeners[0]' + - '{"instance_port": 8081, "instance_protocol": "HTTP", "load_balancer_port": + 8081, "protocol": "HTTP"} == listeners[1]' + vars: + elb: '{{ info.elbs[0] }}' + listeners: "{{ elb.listener_descriptions|map(attribute='listener')|sort(attribute='load_balancer_port') + }}" # ============================================================ # Test getting nonexistent load balancer - - name: get nonexistent load balancer - elb_classic_lb_info: - names: "invalid-elb" - register: info + - name: get nonexistent load balancer + elb_classic_lb_info: + names: invalid-elb + register: info - - assert: - that: - - info.elbs|length==0 + - assert: + that: + - info.elbs|length==0 # Test getting a valid and nonexistent load balancer - - name: get nonexistent load balancer - elb_classic_lb_info: - names: ["{{ elb_name }}", "invalid-elb"] - register: info + - name: get nonexistent load balancer + elb_classic_lb_info: + names: ['{{ elb_name }}', invalid-elb] + register: info - - assert: - that: - - info.elbs|length==1 - - info.elbs[0].load_balancer_name == elb_name + - assert: + that: + - info.elbs|length==1 + - info.elbs[0].load_balancer_name == elb_name # ============================================================ - - name: get all load balancers - elb_classic_lb_info: - names: "{{ omit }}" - register: info + - name: get all load balancers + elb_classic_lb_info: + names: '{{ omit }}' + register: info - - assert: - that: - - info.elbs|length>0 + - assert: + that: + - info.elbs|length>0 always: # ============================================================ - - name: remove the test load balancer completely - elb_classic_lb: - name: "{{ elb_name }}" - state: absent - register: result - ignore_errors: true + - name: remove the test load balancer completely + elb_classic_lb: + name: '{{ elb_name }}' + state: absent + register: result + ignore_errors: true From 83f18ce30680f987651dc0509fd4c43af53ae134 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 30 Sep 2024 12:41:16 -0700 Subject: [PATCH 29/32] Add changelog fragment --- changelogs/fragments/migrate_elb_classic_lb_info.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/fragments/migrate_elb_classic_lb_info.yml diff --git a/changelogs/fragments/migrate_elb_classic_lb_info.yml b/changelogs/fragments/migrate_elb_classic_lb_info.yml new file mode 100644 index 00000000000..60ec869a41e --- /dev/null +++ b/changelogs/fragments/migrate_elb_classic_lb_info.yml @@ -0,0 +1,5 @@ +--- +major_changes: + - elb_classic_lb_info - The module has been migrated from the ``community.aws`` + collection. Playbooks using the Fully Qualified Collection Name for this module + should be updated to use ``amazon.aws.elb_classic_lb_info``. From 0c8cffc1a70581a654a2357a9dc9a43e32c79518 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 30 Sep 2024 12:53:57 -0700 Subject: [PATCH 30/32] update fqdn to amazon.aws.elb_classic_lb_info --- .../elb_classic_lb/tasks/basic_internal.yml | 2 +- .../elb_classic_lb/tasks/basic_public.yml | 2 +- .../targets/elb_classic_lb_info/tasks/main.yml | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/integration/targets/elb_classic_lb/tasks/basic_internal.yml b/tests/integration/targets/elb_classic_lb/tasks/basic_internal.yml index 5a6f9d6c300..e5e043eaad1 100644 --- a/tests/integration/targets/elb_classic_lb/tasks/basic_internal.yml +++ b/tests/integration/targets/elb_classic_lb/tasks/basic_internal.yml @@ -75,7 +75,7 @@ that: - info.network_interfaces | length > 0 - - community.aws.elb_classic_lb_info: + - amazon.aws.elb_classic_lb_info: names: ["{{ elb_name }}"] register: info diff --git a/tests/integration/targets/elb_classic_lb/tasks/basic_public.yml b/tests/integration/targets/elb_classic_lb/tasks/basic_public.yml index c427a50626d..ab5b0b88a60 100644 --- a/tests/integration/targets/elb_classic_lb/tasks/basic_public.yml +++ b/tests/integration/targets/elb_classic_lb/tasks/basic_public.yml @@ -71,7 +71,7 @@ that: - info.network_interfaces | length > 0 - - community.aws.elb_classic_lb_info: + - amazon.aws.elb_classic_lb_info: names: ["{{ elb_name }}"] register: info diff --git a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml index 49bfa7e31fd..438858cb33d 100644 --- a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml +++ b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml @@ -12,7 +12,7 @@ # remove listeners # remove elb -# __elb_classic_lb_info_ +# __amazon.aws.elb_classic_lb_info_ # get nonexistent load balancer - module_defaults: @@ -65,7 +65,7 @@ - '[8080, 8080, "HTTP", "HTTP"] in create.elb.listeners' - name: Get ELB info - elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: names: '{{ elb_name }}' register: info @@ -139,7 +139,7 @@ - update_az.elb.zones[0] == aws_region ~ 'c' - name: Get ELB info after changing AZ's - elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: names: '{{ elb_name }}' register: info @@ -177,7 +177,7 @@ - aws_region ~ 'c' in update_az.elb.zones - name: Get ELB info after updating AZ's - elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: names: '{{ elb_name }}' register: info @@ -216,7 +216,7 @@ - purge_listeners.elb.listeners|length == 1 - name: Get ELB info after purging listeners - elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: names: '{{ elb_name }}' register: info @@ -256,7 +256,7 @@ - update_listeners.elb.listeners|length == 2 - name: Get ELB info after adding listeners - elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: names: '{{ elb_name }}' register: info @@ -276,7 +276,7 @@ # Test getting nonexistent load balancer - name: get nonexistent load balancer - elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: names: invalid-elb register: info @@ -286,7 +286,7 @@ # Test getting a valid and nonexistent load balancer - name: get nonexistent load balancer - elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: names: ['{{ elb_name }}', invalid-elb] register: info @@ -298,7 +298,7 @@ # ============================================================ - name: get all load balancers - elb_classic_lb_info: + amazon.aws.elb_classic_lb_info: names: '{{ omit }}' register: info From 58a0f5af3f3a2c98a44e4cf732779a476ec1264e Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Mon, 30 Sep 2024 12:55:05 -0700 Subject: [PATCH 31/32] update fqdn in tests --- .../targets/elb_classic_lb_info/tasks/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml index 438858cb33d..407933733c4 100644 --- a/tests/integration/targets/elb_classic_lb_info/tasks/main.yml +++ b/tests/integration/targets/elb_classic_lb_info/tasks/main.yml @@ -27,7 +27,7 @@ # create test elb with listeners, certificate, and health check - name: Create ELB - elb_classic_lb: + amazon.aws.elb_classic_lb: name: '{{ elb_name }}' state: present zones: @@ -113,7 +113,7 @@ # Change AZ's - name: Change AZ's - elb_classic_lb: + amazon.aws.elb_classic_lb: name: '{{ elb_name }}' state: present zones: @@ -155,7 +155,7 @@ # Update AZ's - name: Update AZ's - elb_classic_lb: + amazon.aws.elb_classic_lb: name: '{{ elb_name }}' state: present zones: @@ -195,7 +195,7 @@ # Purge Listeners - name: Purge Listeners - elb_classic_lb: + amazon.aws.elb_classic_lb: name: '{{ elb_name }}' state: present zones: @@ -234,7 +234,7 @@ # add Listeners - name: Add Listeners - elb_classic_lb: + amazon.aws.elb_classic_lb: name: '{{ elb_name }}' state: present zones: @@ -310,7 +310,7 @@ # ============================================================ - name: remove the test load balancer completely - elb_classic_lb: + amazon.aws.elb_classic_lb: name: '{{ elb_name }}' state: absent register: result From 7353ecce8f1b6e78e96cff55ae330e0ff3041443 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Thu, 3 Oct 2024 10:36:14 -0700 Subject: [PATCH 32/32] minor fixes based on review feedback --- plugins/modules/elb_classic_lb_info.py | 12 +----------- .../targets/elb_classic_lb_info/meta/main.yml | 1 - .../targets/elb_classic_lb_info/vars/main.yml | 2 -- 3 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 tests/integration/targets/elb_classic_lb_info/meta/main.yml delete mode 100644 tests/integration/targets/elb_classic_lb_info/vars/main.yml diff --git a/plugins/modules/elb_classic_lb_info.py b/plugins/modules/elb_classic_lb_info.py index 29950af068f..308bc89ae39 100644 --- a/plugins/modules/elb_classic_lb_info.py +++ b/plugins/modules/elb_classic_lb_info.py @@ -8,6 +8,7 @@ --- module: elb_classic_lb_info version_added: 1.0.0 +version_added_collection: community.aws short_description: Gather information about EC2 Classic Elastic Load Balancers in AWS description: - Gather information about EC2 Classic Elastic Load Balancers in AWS. @@ -35,28 +36,17 @@ amazon.aws.elb_classic_lb_info: register: elb_info -- ansible.builtin.debug: - msg: "{{ item.dns_name }}" - loop: "{{ elb_info.elbs }}" - - name: Gather information about a particular ELB amazon.aws.elb_classic_lb_info: names: frontend-prod-elb register: elb_info -- ansible.builtin.debug: - msg: "{{ elb_info.elbs.0.dns_name }}" - - name: Gather information about a set of ELBs amazon.aws.elb_classic_lb_info: names: - frontend-prod-elb - backend-prod-elb register: elb_info - -- ansible.builtin.debug: - msg: "{{ item.dns_name }}" - loop: "{{ elb_info.elbs }}" """ RETURN = r""" diff --git a/tests/integration/targets/elb_classic_lb_info/meta/main.yml b/tests/integration/targets/elb_classic_lb_info/meta/main.yml deleted file mode 100644 index 32cf5dda7ed..00000000000 --- a/tests/integration/targets/elb_classic_lb_info/meta/main.yml +++ /dev/null @@ -1 +0,0 @@ -dependencies: [] diff --git a/tests/integration/targets/elb_classic_lb_info/vars/main.yml b/tests/integration/targets/elb_classic_lb_info/vars/main.yml deleted file mode 100644 index 79194af1ef5..00000000000 --- a/tests/integration/targets/elb_classic_lb_info/vars/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for test_ec2_elb_lb