ansible-collections / amazon.aws

Ansible Collection for Amazon AWS
GNU General Public License v3.0
310 stars 336 forks source link

[ec2_asg] fail when update tags inside ASG with KeyError; 'LaunchTemplate #2118

Closed Akasurde closed 2 months ago

Akasurde commented 4 months ago

Summary

`trying to add new tag inside my current ASG created before seems apply changes but appears this error and break

Issue Type

Bug Report

Component Name

ec2_asg

Ansible Version

$ ansible --version
ansible [core 2.16.6]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/.local/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.4
  libyaml = True

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
# Since Ansible 2.12 (core):
# To generate an example config file (a "disabled" one with all default settings, commented out):
#               $ ansible-config init --disabled > ansible.cfg
#
# Also you can now have a more complete file by including existing plugins:
# ansible-config init --disabled -t all > ansible.cfg

# For previous versions of Ansible you can check for examples in the 'stable' branches of each version
# Note that this file was always incomplete  and lagging changes to configuration settings

# for example, for 2.9: https://github.com/ansible/ansible/blob/stable-2.9/examples/ansible.cfg

OS / Environment

Ubuntu 22.04 WSL

Steps to Reproduce

    name: Get Auto Scaling Groups for EKS cluster
      amazon.aws.autoscaling_group_info:
        tags:
          eks:cluster-name: add-tags-asg
      register: asg_info

   name: Add new tag to Auto Scaling Groups
      amazon.aws.autoscaling_group:
        name: "{{ item.auto_scaling_group_name }}"
        tags:
          - Product: new tag
            propagate_at_launch: true
      loop: "{{ asg_info.results }}"
      register: asg_update

   debug: msg="{{ asg_update.stderr }}"`

Expected Results

New tag added to ASG

Actual Results

` 
Traceback (most recent call last):
  File "/tmp/ansible_amazon.aws.autoscaling_group_payload_s3ziqwd6/ansible_amazon.aws.autoscaling_group_payload.zip/ansible_collections/amazon/aws/plugins/modules/autoscaling_group.py", line 1399, in create_autoscaling_group
KeyError: 'LaunchConfigurationName'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.ansible/tmp/ansible-tmp-1717076495.9101698-178940-110762071316883/AnsiballZ_autoscaling_group.py", line 107, in <module>
    _ansiballz_main()
  File "/home/user/.ansible/tmp/ansible-tmp-1717076495.9101698-178940-110762071316883/AnsiballZ_autoscaling_group.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/user/.ansible/tmp/ansible-tmp-1717076495.9101698-178940-110762071316883/AnsiballZ_autoscaling_group.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.amazon.aws.plugins.modules.autoscaling_group', init_globals=dict(_module_fqn='ansible_collections.amazon.aws.plugins.modules.autoscaling_group', _modlib_path=modlib_path),
  File "/usr/lib/python3.10/runpy.py", line 224, 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_amazon.aws.autoscaling_group_payload_s3ziqwd6/ansible_amazon.aws.autoscaling_group_payload.zip/ansible_collections/amazon/aws/plugins/modules/autoscaling_group.py", line 2005, in <module>
  File "/tmp/ansible_amazon.aws.autoscaling_group_payload_s3ziqwd6/ansible_amazon.aws.autoscaling_group_payload.zip/ansible_collections/amazon/aws/plugins/modules/autoscaling_group.py", line 1977, in main
  File "/tmp/ansible_amazon.aws.autoscaling_group_payload_s3ziqwd6/ansible_amazon.aws.autoscaling_group_payload.zip/ansible_collections/amazon/aws/plugins/modules/autoscaling_group.py", line 1401, in create_autoscaling_group
KeyError: 'LaunchTemplate'
`

Code of Conduct

Akasurde commented 4 months ago

cc @thinkopensource

Akasurde commented 4 months ago

@thinkopensource This code is only to add new tags to and existing ASG, so there is no template or launchconfig. The objective is to replicate this command in ansible module aws autoscaling create-or-update-tags --tags ResourceId=my-eks,ResourceType=auto-scaling-group,Key=New tag,Value=New Value,PropagateAtLaunch=true

gravesm commented 3 months ago

@thinkopensource can you provide the version of the collection you are using?

thinkopensource commented 3 months ago

.local/lib/python3.10/site-packages/ansible_collections Collection Version


amazon.aws 7.5.0 community.aws 7.2.0

/usr/lib/python3/dist-packages/ansible_collections

Collection Version


amazon.aws 7.6.0 community.aws 7.2.0

But is true that appears 2 times, can affect this?

GomathiselviS commented 3 months ago

Hi @Akasurde @thinkopensource,

I tried adding a tag to the existing ASG and didn't encounter any issues with both the latest amazon.aws collection and amazon.aws 7.5.0. From the module code, it appears that if the ASG exists, the launch template for the ASG will be available and won't result in the error mentioned above. Could you please share the output of asg_info from the playbook above? Additionally, please refer to a similar task used for testing this module.

GomathiselviS commented 2 months ago

Hi @Akasurde @thinkopensource , since the issue is not reproducible from our end, I am closing this issue. If you happen to reencounter the issue, please feel free to reopen it.