Ansible ec2_asg模块找不到启动配置

时间:2018-01-14 19:29:03

标签: ansible

我试图让Ansible创建启动配置(使用ec2_lc)和自动缩放组(ec2_asg)。我的playbook创建了启动配置,但是ASG正在创建一个错误:

fatal: [localhost -> localhost]: FAILED! => {"changed": false, "msg": "No launch config found with name {'name': 'dockerLC', 'instance_type': 't2.micro', 'image_id': 'ami-e97c548c', 'changed': False, 'failed': False, 'arn': None, 'created_time': 'None', 'security_groups': ['sg-e0c0de88'], 'result': {'image_id': 'ami-e97c548c', 'key_name': 'ansible-keys', 'launch_configuration_name': 'dockerLC', 'ebs_optimized': False, 'instance_type': 't2.micro', 'created_time': 'None', 'associate_public_ip_address': True, 'instance_monitoring': False, 'placement_tenancy': 'default', 'security_groups': ['sg-e0c0de88'], 'block_device_mappings': []}}"}

我不确定为什么会抛出此错误,因为我在AWS EC2 Web界面中肯定有dockerLC启动配置。我的剧本如下。

  tasks:
    - name: Create Launch Configuration
      local_action:
        module: ec2_lc
        name: dockerLC
        region: '{{ aws_region }}'
        image_id: '{{ ami_id }}'
        key_name: '{{ key_name }}'
        security_groups: '{{ security_group_id }}'
        # security_groups: '{{ security_group }}'
        instance_type: '{{ instance_type }}'
        assign_public_ip: True
        vpc_id: '{{ vpc }}'
      register: lc
    # - pause:
    #     seconds: 10
    - name: Create Auto Scaling Group
      local_action:
        module: ec2_asg
        name: dockerASG
        region: '{{ aws_region }}'
        launch_config_name: '{{ lc }}'
        min_size: 3
        max_size: 5
        wait_for_instances: True
        availability_zones: ['us-east-2a', 'us-east-2b', 'us-east-2c']
        vpc_zone_identifier: ' {{ vpc_zones }} '
        tags:
          - function: docker
            billingGroup: Work

1 个答案:

答案 0 :(得分:0)

当您为任务注册变量时,变量通常是包含更多信息而不仅仅是字符串的哈希。在这种情况下,有一个哈希包含:

i.getId()

{ 'name':'dockerLC', 'instance_type':'t2.micro', 'image_id':'ami-e97c548c', 'changed':False, 'failed':False, 'arn':None, 'created_time':'None', 'security_groups':[ 'sg-e0c0de88' ], 'result':{ 'image_id':'ami-e97c548c', 'key_name':'ansible-keys', 'launch_configuration_name':'dockerLC', 'ebs_optimized':False, 'instance_type':'t2.micro', 'created_time':'None', 'associate_public_ip_address':True, 'instance_monitoring':False, 'placement_tenancy':'default', 'security_groups':[ 'sg-e0c0de88' ], 'block_device_mappings':[ ] } } 只想将名称作为字符串。在这种情况下,您希望引用launch_config_name这是启动配置的名称。您也可以使用可用的launch_config_name: '{{ lc.name }}'(作为示例)。