You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在AWS EC2创建Auto Scaling组时遭遇KeyError: 'launch_config_name'问题

问题分析

你遇到的KeyError: 'launch_config_name'是Ansible community.aws.ec2_asg模块的兼容性问题,常见于Ansible 2.12.x搭配旧版本community.aws集合的场景。即便你未使用Launch Configuration参数,模块内部处理Launch Template时,仍会尝试读取launch_config_name字段,进而抛出KeyError。而AWS控制台显示ASG已正常关联Launch Template,是因为模块实际已完成ASG创建操作,报错发生在后续的状态校验或数据处理阶段。

解决方案

以下几种方法可解决该问题:

  • 升级community.aws集合版本
    该bug在community.aws集合3.0.0及以上版本已被修复。执行命令升级集合:

    ansible-galaxy collection install community.aws:>=3.0.0 -f
    
  • 显式设置空的launch_configuration_name参数
    在create auto scaling group任务中添加launch_configuration_name: "",强制覆盖模块内部的默认读取逻辑,避免触发KeyError:

    - name: create auto scaling group
      community.aws.ec2_asg:
        name: "{{ service }}"
        state: present
        region: "{{ region }}"
        load_balancers: "{{  service +'-lb' }}"
        target_group_arns:
          - "{{ service_target_group_arn }}"
        launch_template:
          launch_template_name: "{{ service }}-lt-{{ date.stdout }}"
        launch_configuration_name: ""  # 添加此行
        health_check_period: "{{ health_check_period }}"
        health_check_type: "{{ health_check_type }}"
        metrics_collection: yes
        replace_all_instances: yes
        replace_batch_size: "{{ max_size|int - desired_capacity|int }}"
        min_size: "{{ min_size }}"
        max_size: "{{ max_size }}"
        desired_capacity: "{{ desired_capacity }}"
        vpc_zone_identifier:
          - "{{ p1 }}"
          - "{{ p2 }}"
        wait_for_instances: true 
        wait_timeout: "{{ wait_timeout }}"
    
  • 排查变量冲突
    确认Playbook或主机变量中未意外定义launch_config_name变量,防止模块错误读取该变量值。

内容的提问来源于stack exchange,提问作者Omri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 09:55:10