如何使用ansible将负载均衡器添加到aws ecs服务

How to add load balancer to aws ecs service with ansible

我想用 ansibleload balancer 添加到 ecs service 模块。因此,我使用以下代码:

- 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

returns 出现以下错误:

raise ParamValidationError(report=report.generate_report())\nbotocore.exceptions.ParamValidationError: Parameter validation failed:\nInvalid type for parameter loadBalancers[0], value: name_of_my_load_balancer, type: , valid types: \n"

它需要一个包含目标组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