如何使用Ansible将负载均衡器添加到AWS ECS服务

时间:2019-10-14 12:48:52

标签: amazon-web-services ansible amazon-ecs amazon-elb

我想使用load balancerecs service模块添加ansible。因此,我正在使用以下代码:

- name: create ECS service on VPC network
  ecs_service:
    state: present
    name: console-test-service
    cluster: new_cluster
    desired_count: 0
    network_configuration:
      subnets:
      - subnet-abcd1234
      security_groups:
      - sg-aaaa1111
      - my_security_group

现在,我想使用load_balancers参数添加负载均衡器。但是,这是负载平衡器列表。如何添加要定义的负载均衡器名称列表?

例如:

load_balancers: 
   - name_of_my_load_balancer

返回以下错误:

  

提高   ParamValidationError(report = report.generate_report())\ nbotocore.exceptions.ParamValidationError:   参数验证失败:\ n参数类型无效   loadBalancers [0],值:name_of_my_load_balancer,类型:,有效   类型:\ n“

1 个答案:

答案 0 :(得分:1)

它需要一个包含目标组ARN,容器名称和容器端口的字典。

- name: create ECS service on VPC network
  ecs_service:
    state: present
    name: console-test-service
    cluster: new_cluster
    desired_count: 0
    load_balancers:
      - targetGroupArn: arn:aws:elasticloadbalancing:eu-west-1:453157221:targetgroup/tg/16331647320e8a42
        containerName: laravel
        containerPort: 80
    network_configuration:
      subnets:
      - subnet-abcd1234
      security_groups:
      - sg-aaaa1111
      - my_security_group