Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with community.aws.elb_application_lb #1089

Closed
1 task done
Scaramush opened this issue Apr 21, 2022 · 5 comments · Fixed by ansible-collections/amazon.aws#929
Closed
1 task done

Issue with community.aws.elb_application_lb #1089

Scaramush opened this issue Apr 21, 2022 · 5 comments · Fixed by ansible-collections/amazon.aws#929
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) python3 traceback

Comments

@Scaramush
Copy link

Summary

When I try to add ALB listener config with weighted routes playbook fails

Issue Type

Bug Report

Component Name

elb_application_lb

Ansible Version

$ ansible --version
ansible 2.9.16
  config file = None
  configured module search path = ['/home/alex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Mar 24 2022, 13:07:27) [GCC 11.2.0]

Collection Versions

aws.amazon Changelog
===========================
community.aws Release Notes
===========================

.. contents:: Topics


v3.2.0
======

Minor Changes
-------------

- aws_secret - add pagination for ``bypath`` functionality (https://github.com/ansible-collections/amazon.aws/pull/591).
- ec2_instance - Fix scope of deprecation warning to not show warning when ``state`` in ``absent`` (https://github.com/ansible-collections/amazon.aws/pull/719).
- ec2_vpc_route_table - support associating internet gateways (https://github.com/ansible-collections/amazon.aws/pull/690).
- module_utils.elbv2 - Add support for alb specific attributes and compare_elb_attributes method to support check_mode in module_utils.elbv2 (https://github.com/ansible-collections/amazon.
aws/pull/696).
- s3_bucket - Add support for enforced bucket owner object ownership (https://github.com/ansible-collections/amazon.aws/pull/694).

comunity.amazon Changelog
===========================
community.aws Release Notes
===========================

.. contents:: Topics


v3.2.1
======

Release Summary
---------------

This is a bugfix release of the ``community.aws`` collection.
The new parameter ``purge_tags`` in ``ec2_asg`` module, that
was introduced in ``community.aws 3.2.0`` with its default
value ``true``, possibly breaks existing playbooks for users
if they don't update their playbooks and specify
``purge_tags: false``. However, this release restores the
previous behaviour.

AWS SDK versions

Name: boto
Version: 2.49.0
Summary: Amazon Web Services Library
Home-page: https://github.com/boto/boto/
Author: Mitch Garnaat
Author-email: [email protected]
License: MIT
Location: /usr/lib/python3/dist-packages
Requires: 
Required-by: 
---
Name: boto3
Version: 1.20.34
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Location: /usr/lib/python3/dist-packages
Requires: 
Required-by: 
---
Name: botocore
Version: 1.23.34
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Location: /usr/lib/python3/dist-packages
Requires: 
Required-by: 

Configuration

$ ansible-config dump --only-changed

OS / Environment

Debian bookworm/sid

Steps to Reproduce

- community.aws.elb_application_lb:
    name: "{{ alb_name }}"
    region: "{{ aws_region }}"
    scheme: "{{ alb_info.load_balancers[0].scheme }}"
    security_groups: "{{ alb_info.load_balancers[0].security_groups }}"
    subnets: "{{ subnet_ids }}"
    listeners:
      - Protocol: HTTP
        Port: 80
        DefaultActions: 
          - Type: forward
            TargetGroupName: '{{ tg_name }}'
        Rules:
          - Conditions:
            - Field: path-pattern
              Values:
                - '/some_path*'
            Priority: '1'
            Actions:
              - Type: forward
                ForwardConfig:
                  TargetGroups:
                    - TargetGroupArn: "tg1_arn"
                      Weight: 5
                    - TargetGroupArn: "tg2_arn"
                      Weight: 95
    state: present

Expected Results

AWS ALB Listener updated with two weighted TGs

Actual Results

The full traceback is:
Traceback (most recent call last):
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 102, in <module>
    _ansiballz_main()
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.elb_application_lb', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.10/runpy.py", line 209, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 821, in <module>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 815, in main
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 653, in create_or_update_alb
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 928, in compare_rules
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in _compare_rule
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in <listcomp>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 29, in _prune_ForwardConfig
KeyError: 'TargetGroupArn'

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module needs_triage plugins plugin (any type) python3 traceback labels Apr 21, 2022
@markuman
Copy link
Member

markuman commented May 6, 2022

If this is the right syntax

           Actions:
              - Type: forward
                ForwardConfig:
                  TargetGroups:
                    - TargetGroupArn: "tg1_arn"
                      Weight: 5
                    - TargetGroupArn: "tg2_arn"
                      Weight: 95

then it's a bug in amazon.aws plugins/module_utils/elbv2.py.
The function does not verify what its comment is told :)

# ForwardConfig may be optional if we've got a single TargetGroupArn entry

I think someone must move this issue into amazon.aws, because community.aws cannot fix the error.

cc @alinabuzachis @jatorcasso @tremble

@tremble
Copy link
Contributor

tremble commented Jul 15, 2022

Hi @Scaramush,

sorry it's taken so long. I've submitted ansible-collections/amazon.aws#929 which should fix the issue. If you're able to test and confirm this fixes the issue that would help.

@Scaramush
Copy link
Author

I've checked playbook with updated plugin and looks like it works fine now. Thanks a lot

softwarefactory-project-zuul bot pushed a commit to ansible-collections/amazon.aws that referenced this issue Jul 15, 2022
elbv2 - Fix KeyError when passing two TGs

SUMMARY
Fixes: ansible-collections/community.aws#1089
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/module_utils/elbv2.py
ADDITIONAL INFORMATION
Based on the docs, if you want to balance across multiple TGs you shouldn't pass a TargetGroupArn, and instead just the ForwardConfig.  (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.create_listener)

The Amazon Resource Name (ARN) of the target group. Specify only when Type is forward and you want to route to a single target group. To route to one or more target groups, use ForwardConfig instead.

However, it is also valid (but redundant) to Pass the ARN and a ForwardConfig

If you specify both ForwardConfig and TargetGroupArn, you can specify only one target group using ForwardConfig and it must be the same target group specified in TargetGroupArn.

Original Error:
The full traceback is:
Traceback (most recent call last):
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 102, in <module>
    _ansiballz_main()
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.elb_application_lb', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.10/runpy.py", line 209, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 821, in <module>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 815, in main
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 653, in create_or_update_alb
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 928, in compare_rules
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in _compare_rule
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in <listcomp>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 29, in _prune_ForwardConfig
KeyError: 'TargetGroupArn'

Reviewed-by: Alina Buzachis <None>
patchback bot pushed a commit to ansible-collections/amazon.aws that referenced this issue Jul 15, 2022
elbv2 - Fix KeyError when passing two TGs

SUMMARY
Fixes: ansible-collections/community.aws#1089
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/module_utils/elbv2.py
ADDITIONAL INFORMATION
Based on the docs, if you want to balance across multiple TGs you shouldn't pass a TargetGroupArn, and instead just the ForwardConfig.  (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.create_listener)

The Amazon Resource Name (ARN) of the target group. Specify only when Type is forward and you want to route to a single target group. To route to one or more target groups, use ForwardConfig instead.

However, it is also valid (but redundant) to Pass the ARN and a ForwardConfig

If you specify both ForwardConfig and TargetGroupArn, you can specify only one target group using ForwardConfig and it must be the same target group specified in TargetGroupArn.

Original Error:
The full traceback is:
Traceback (most recent call last):
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 102, in <module>
    _ansiballz_main()
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.elb_application_lb', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.10/runpy.py", line 209, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 821, in <module>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 815, in main
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 653, in create_or_update_alb
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 928, in compare_rules
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in _compare_rule
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in <listcomp>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 29, in _prune_ForwardConfig
KeyError: 'TargetGroupArn'

Reviewed-by: Alina Buzachis <None>
(cherry picked from commit 0b97186)
patchback bot pushed a commit to ansible-collections/amazon.aws that referenced this issue Jul 15, 2022
elbv2 - Fix KeyError when passing two TGs

SUMMARY
Fixes: ansible-collections/community.aws#1089
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/module_utils/elbv2.py
ADDITIONAL INFORMATION
Based on the docs, if you want to balance across multiple TGs you shouldn't pass a TargetGroupArn, and instead just the ForwardConfig.  (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.create_listener)

The Amazon Resource Name (ARN) of the target group. Specify only when Type is forward and you want to route to a single target group. To route to one or more target groups, use ForwardConfig instead.

However, it is also valid (but redundant) to Pass the ARN and a ForwardConfig

If you specify both ForwardConfig and TargetGroupArn, you can specify only one target group using ForwardConfig and it must be the same target group specified in TargetGroupArn.

Original Error:
The full traceback is:
Traceback (most recent call last):
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 102, in <module>
    _ansiballz_main()
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.elb_application_lb', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.10/runpy.py", line 209, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 821, in <module>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 815, in main
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 653, in create_or_update_alb
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 928, in compare_rules
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in _compare_rule
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in <listcomp>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 29, in _prune_ForwardConfig
KeyError: 'TargetGroupArn'

Reviewed-by: Alina Buzachis <None>
(cherry picked from commit 0b97186)
softwarefactory-project-zuul bot pushed a commit to ansible-collections/amazon.aws that referenced this issue Jul 15, 2022
[PR #929/0b97186c backport][stable-3] elbv2 - Fix KeyError when passing two TGs

This is a backport of PR #929 as merged into main (0b97186).
SUMMARY
Fixes: ansible-collections/community.aws#1089
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/module_utils/elbv2.py
ADDITIONAL INFORMATION
Based on the docs, if you want to balance across multiple TGs you shouldn't pass a TargetGroupArn, and instead just the ForwardConfig.  (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.create_listener)

The Amazon Resource Name (ARN) of the target group. Specify only when Type is forward and you want to route to a single target group. To route to one or more target groups, use ForwardConfig instead.

However, it is also valid (but redundant) to Pass the ARN and a ForwardConfig

If you specify both ForwardConfig and TargetGroupArn, you can specify only one target group using ForwardConfig and it must be the same target group specified in TargetGroupArn.

Original Error:
The full traceback is:
Traceback (most recent call last):
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 102, in <module>
    _ansiballz_main()
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.elb_application_lb', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.10/runpy.py", line 209, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 821, in <module>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 815, in main
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 653, in create_or_update_alb
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 928, in compare_rules
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in _compare_rule
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in <listcomp>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 29, in _prune_ForwardConfig
KeyError: 'TargetGroupArn'

Reviewed-by: Mark Chappell <None>
softwarefactory-project-zuul bot pushed a commit to ansible-collections/amazon.aws that referenced this issue Jul 15, 2022
[PR #929/0b97186c backport][stable-4] elbv2 - Fix KeyError when passing two TGs

This is a backport of PR #929 as merged into main (0b97186).
SUMMARY
Fixes: ansible-collections/community.aws#1089
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/module_utils/elbv2.py
ADDITIONAL INFORMATION
Based on the docs, if you want to balance across multiple TGs you shouldn't pass a TargetGroupArn, and instead just the ForwardConfig.  (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.create_listener)

The Amazon Resource Name (ARN) of the target group. Specify only when Type is forward and you want to route to a single target group. To route to one or more target groups, use ForwardConfig instead.

However, it is also valid (but redundant) to Pass the ARN and a ForwardConfig

If you specify both ForwardConfig and TargetGroupArn, you can specify only one target group using ForwardConfig and it must be the same target group specified in TargetGroupArn.

Original Error:
The full traceback is:
Traceback (most recent call last):
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 102, in <module>
    _ansiballz_main()
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/alex/.ansible/tmp/ansible-tmp-1650531340.4967074-29141-25081229266719/AnsiballZ_elb_application_lb.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.elb_application_lb', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.10/runpy.py", line 209, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 821, in <module>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 815, in main
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/community/aws/plugins/modules/elb_application_lb.py", line 653, in create_or_update_alb
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 928, in compare_rules
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in _compare_rule
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 894, in <listcomp>
  File "/tmp/ansible_community.aws.elb_application_lb_payload_dy92ctf5/ansible_community.aws.elb_application_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/elbv2.py", line 29, in _prune_ForwardConfig
KeyError: 'TargetGroupArn'

Reviewed-by: Mark Chappell <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) python3 traceback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants