Ansible:找不到自动缩放组的新创建/旧的启动配置

时间:2019-06-17 14:50:05

标签: amazon-web-services ansible

我正在一个Ansible项目中创建启动配置。之后,我尝试将其添加到自动缩放组中。但它总是说,找不到启动配置。我究竟做错了什么?我可以在AWS控制台中看到现有的启动配置。

错误日志:

fatal: [127.0.0.1]: FAILED! => {"changed": false, "msg": "No launch config found with name Magento_Launch_Config"}

代码:

- hosts: localhost
  connection: local
  gather_facts: no
  tasks:
     - name: create launch config
       ec2_lc:
          name: Magento_Launch_Config
          image_id: "{{ ec2found.instances.0.image_id }}"
          region: eu-central-1
          security_groups: [ 'SG1', 'SG2']
          instance_type: c5n.large
          assign_public_ip: yes
       register: lc

- hosts: localhost
  connection: local
  gather_facts: no
  tasks:
     - name: Add auto-scaling groups.
       ec2_asg:
          name: magento_scaling_group
          load_balancers: [ 'magento_scaling_group' ]
          availability_zones: [ 'eu-central-1a', 'eu-central-1b', 'eu-central-1c' ]
          launch_config_name: "{{ lc.name }}"
          min_size: 1
          max_size: 5
          desired_capacity: 1
          vpc_zone_identifier: [ 'subnet-e712ad8c', 'subnet-e12e8dac', 'subnet-28e91a55' ]
          tags:
             - environment: test
               propagate_at_launch: no

1 个答案:

答案 0 :(得分:1)

正确的解决方法是对两者都使用模块的region:属性,因此剧本的运行独立于本地用户的awscli配置:

- hosts: localhost
  connection: local
  gather_facts: no
  vars:
    aws_region: eu-central-1
  tasks:
     - name: create launch config
       ec2_lc:
          name: Magento_Launch_Config
          image_id: "{{ ec2found.instances.0.image_id }}"
          region: '{{ aws_region }}'
          security_groups: [ 'SG1', 'SG2']
          instance_type: c5n.large
          assign_public_ip: yes
       register: lc

     - name: Add auto-scaling groups.
       ec2_asg:
          name: magento_scaling_group
          load_balancers: [ 'magento_scaling_group' ]
          availability_zones: [ 'eu-central-1a', 'eu-central-1b', 'eu-central-1c' ]
          launch_config_name: "{{ lc.name }}"
          min_size: 1
          max_size: 5
          desired_capacity: 1
          region: '{{ aws_region }}'
          vpc_zone_identifier: [ 'subnet-e712ad8c', 'subnet-e12e8dac', 'subnet-28e91a55' ]
          tags:
             - environment: test
               propagate_at_launch: no