community.aws.elb_target_group 模块 – 管理应用程序或网络负载均衡器的目标组

注意

此模块是 community.aws 集合(版本 9.0.0)的一部分。

如果您正在使用 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.aws。您需要满足其他要求才能使用此模块,请参阅 要求 了解详细信息。

要在 playbook 中使用它,请指定:community.aws.elb_target_group

community.aws 1.0.0 中的新增功能

概要

要求

在执行此模块的主机上需要满足以下要求。

  • python >= 3.6

  • boto3 >= 1.28.0

  • botocore >= 1.31.0

参数

参数

注释

access_key

别名:aws_access_key_id, aws_access_key, ec2_access_key

字符串

AWS 访问密钥 ID。

有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys

也可以使用 AWS_ACCESS_KEY_IDAWS_ACCESS_KEYEC2_ACCESS_KEY 环境变量,优先级依次降低。

aws_access_keyprofile 选项是互斥的。

为了与 AWS botocore SDK 保持一致,在版本 5.1.0 中添加了 aws_access_key_id 别名。

ec2_access_key 别名已被弃用,将在 2024-12-01 之后的版本中删除。

EC2_ACCESS_KEY 环境变量的支持已被弃用,将在 2024-12-01 之后的版本中删除。

aws_ca_bundle

路径

用于验证 SSL 证书的 CA 包的位置。

也可以使用 AWS_CA_BUNDLE 环境变量。

aws_config

字典

用于修改 botocore 配置的字典。

可以在 AWS 文档中找到参数 https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config

debug_botocore_endpoint_logs

布尔值

使用 botocore.endpoint 记录器来解析任务期间进行的唯一(而不是总计)"resource:action" API 调用,将该集合输出到任务结果中的 resource_actions 键。使用 aws_resource_action 回调输出到 playbook 期间生成的总列表。

也可以使用 ANSIBLE_DEBUG_BOTOCORE_LOGS 环境变量。

选项

  • false ← (默认)

  • true

deregistration_connection_termination

布尔值

在 community.aws 3.1.0 中添加

指示负载均衡器是否在取消注册超时结束时终止连接。

仅当附加到网络负载均衡器 (NLB) 时才支持使用此选项。

选项

  • false ← (默认)

  • true

deregistration_delay_timeout

整数

弹性负载均衡在将取消注册目标的的状态从 draining 更改为 unused 之前等待的时间。范围是 0-3600 秒。

endpoint_url

别名:ec2_url, aws_endpoint_url, s3_url

字符串

要连接的 URL,而不是默认的 AWS 端点。虽然这可以用于连接到其他 AWS 兼容服务,但 amazon.aws 和 community.aws 集合仅针对 AWS 进行了测试。

可以使用 AWS_URLEC2_URL 环境变量,优先级递减。

ec2_urls3_url 别名已被弃用,将在 2024-12-01 之后的版本中移除。

EC2_URL 环境变量的支持已被弃用,将在 2024-12-01 之后的版本中移除。

health_check_interval

整数

对单个目标进行健康检查的大概时间间隔,以秒为单位。

health_check_path

字符串

作为健康检查目标的 ping 路径。必须定义此路径才能设置健康检查。

需要设置 health_check_protocol 参数。

health_check_port

字符串

负载均衡器在对目标执行健康检查时使用的端口。可以设置为“traffic-port”以匹配目标端口。

如果未定义,则默认为每个目标从负载均衡器接收流量的端口。

health_check_protocol

字符串

负载均衡器在对目标执行健康检查时使用的协议。

选项

  • "http"

  • "https"

  • "tcp"

  • "tls"

  • "udp"

  • "tcp_udp"

  • "HTTP"

  • "HTTPS"

  • "TCP"

  • "TLS"

  • "UDP"

  • "TCP_UDP"

health_check_timeout

整数

在多少秒内,如果目标没有响应则表示健康检查失败。

healthy_threshold_count

整数

将不健康的目标视为健康所需连续健康检查成功的次数。

load_balancing_algorithm_type

字符串

在 community.aws 3.2.0 中添加

要使用的负载均衡算法的类型。

仅当与应用程序负载均衡器 (ALB) 一起使用时,才支持更改负载均衡算法。

如果未设置,AWS 将默认为 round_robin

选项

  • "round_robin"

  • "least_outstanding_requests"

modify_targets

布尔值

是否更改组中现有的目标以匹配模块传递的内容

选项

  • false

  • true ← (默认)

name

string / 必填

目标组的名称。

port

整数

目标接收流量的端口。除非在注册目标时指定端口覆盖,否则将使用此端口。

statepresenttarget_typeinstanceipalb 时,此项为必填项。

preserve_client_ip_enabled

布尔值

在 community.aws 2.1.0 中添加

指示是否启用客户端 IP 保留。

如果目标组类型为 ip 地址且目标组协议为 tcptls,则默认禁用。否则,默认启用。对于 udptcp_udp 目标组,不能禁用客户端 IP 保留。

preserve_client_ip_enabled 仅受网络负载均衡器支持。

选项

  • false

  • true

profile

别名: aws_profile

字符串

用于身份验证的命名 AWS 配置文件。

有关命名配置文件的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

也可以使用 AWS_PROFILE 环境变量。

profile 选项与 aws_access_keyaws_secret_keysecurity_token 选项互斥。

protocol

字符串

用于将流量路由到目标的协议。

statepresenttarget_typeinstanceipalb 时,此项为必填项。

选项

  • "http"

  • "https"

  • "tcp"

  • "tls"

  • "udp"

  • "tcp_udp"

  • "HTTP"

  • "HTTPS"

  • "TCP"

  • "TLS"

  • "UDP"

  • "TCP_UDP"

protocol_version

字符串

在 community.aws 5.1.0 中添加

指定协议版本。

protocol_version 参数是不可变的,并且在更新 elb_target_group 时无法更改。

选项

  • "GRPC"

  • "HTTP1"

  • "HTTP2"

proxy_protocol_v2_enabled

布尔值

在 community.aws 2.1.0 中添加

指示是否启用代理协议版本 2。

该值为 truefalse

proxy_protocol_v2_enabled 仅受网络负载均衡器支持。

选项

  • false

  • true

purge_tags

布尔值

如果 purge_tags=true 且设置了 tags,则将从资源中清除现有标签,以完全匹配 tags 参数定义的标签。

如果未设置 tags 参数,即使 purge_tags=True,也不会修改标签。

aws: 开头的标签键由 Amazon 保留,无法修改。因此,出于 purge_tags 参数的目的,它们将被忽略。有关更多信息,请参阅 Amazon 文档 https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html#tag-conventions

选项

  • false

  • true ← (默认)

region

别名: aws_region, ec2_region

字符串

要使用的 AWS 区域。

对于 IAM、Route53 和 CloudFront 等全局服务,将忽略 region

可以使用 AWS_REGIONEC2_REGION 环境变量。

有关更多信息,请参阅 Amazon AWS 文档 http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region

ec2_region 别名已被弃用,将在 2024-12-01 之后的版本中移除

EC2_REGION 环境变量的支持已被弃用,将在 2024-12-01 之后的版本中移除。

secret_key

别名: aws_secret_access_key, aws_secret_key, ec2_secret_key

字符串

AWS 私有访问密钥。

有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys

也可以使用 AWS_SECRET_ACCESS_KEYAWS_SECRET_KEYEC2_SECRET_KEY 环境变量,优先级递减。

secret_keyprofile 选项互斥。

为了与 AWS botocore SDK 保持一致,在 5.1.0 版本中添加了 aws_secret_access_key 别名。

ec2_secret_key 别名已被弃用,将在 2024-12-01 之后的版本中移除。

EC2_SECRET_KEY 环境变量的支持已被弃用,将在 2024-12-01 之后的版本中移除。

session_token

别名: aws_session_token, security_token, aws_security_token, access_token

字符串

用于临时凭证的 AWS STS 会话令牌。

有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys

也可以使用 AWS_SESSION_TOKENAWS_SECURITY_TOKENEC2_SECURITY_TOKEN 环境变量,优先级递减。

security_tokenprofile 选项互斥。

在 3.2.0 版本中添加了别名 aws_session_tokensession_token,该参数在 6.0.0 版本中从 security_token 重命名为 session_token

security_tokenaws_security_tokenaccess_token 别名已被弃用,将在 2024-12-01 之后的版本中移除。

EC2_SECRET_KEYAWS_SECURITY_TOKEN 环境变量的支持已被弃用,将在 2024-12-01 之后的版本中移除。

state

string / 必填

创建或销毁目标组。

选项

  • "present"

  • "absent"

整数

在 community.aws 1.5.0 中添加

客户端请求应路由到同一目标的时间段(以秒为单位)。在此时间段到期后,应用程序生成的 Cookie 将被视为过期。范围为 1 秒到 1 周(604800 秒)。

字符串

在 community.aws 1.5.0 中添加

应用程序 Cookie 的名称。如果 stickiness_type=app_cookie,则为必填项。

stickiness_enabled

布尔值

指示是否启用粘性会话。

选项

  • false

  • true

整数

客户端请求应被路由到同一目标的时间段,以秒为单位。在此时间段到期后,负载均衡器生成的 Cookie 将被视为过期。范围为 1 秒到 1 周(604800 秒)。

stickiness_type

字符串

粘性会话的类型。

有效值为 lb_cookieapp_cookiesource_ip

如果未设置,对于应用程序负载均衡器,AWS 将默认为 lb_cookie,对于网络负载均衡器,将默认为 source_ip

successful_response_codes

字符串

用于检查目标是否成功响应的 HTTP 代码。

接受多个值(例如,“200,202”)或值范围(例如,“200-299”)。

需要设置 health_check_protocol 参数。

tags

别名: resource_tags

字典

一个表示要应用于资源的标签的字典。

如果未设置 tags 参数,则不会修改标签。

target_type

字符串

向此目标组注册目标时必须指定的目标类型。可能的值为 instance(目标由实例 ID 指定)、 ip(目标由 IP 地址指定)、 lambda(目标由 ARN 指定)或 alb(目标由 ARN 指定)。请注意,您不能使用多种类型为目标组指定目标。“lambda”和“alb”目标类型仅接受一个目标。当指定多个目标时,仅使用第一个目标。所有其他目标都将被忽略。如果目标类型为“ip”,请从目标组的虚拟私有云 (VPC) 的子网中指定 IP 地址,即 RFC 1918 范围 (10.0.0.0/8、172.16.0.0/12 和 192.168.0.0/16) 和 RFC 6598 范围 (100.64.0.0/10)。您不能指定公共可路由的 IP 地址。

默认行为是 instance

选项

  • "instance"

  • "ip"

  • "lambda"

  • "alb"

targets

list / elements=dictionary

要分配给目标组的目标列表。此参数默认为空列表。除非您设置了“modify_targets”参数,否则所有现有目标都将从该组中删除。该列表应包含 Id 和 Port 参数。有关详细信息,请参阅示例。

unhealthy_threshold_count

整数

在将目标视为不健康之前,需要连续进行多少次运行状况检查失败。

validate_certs

布尔值

设置为 false 时,将不会验证与 AWS API 通信的 SSL 证书。

强烈建议不要设置 validate_certs=false ,作为替代方案,请考虑设置 aws_ca_bundle

选项

  • false

  • true ← (默认)

vpc_id

字符串

虚拟私有云 (VPC) 的标识符。

statepresenttarget_typeinstanceipalb 时,此项为必填项。

wait

布尔值

是否等待目标组。

选项

  • false ← (默认)

  • true

wait_timeout

整数

等待目标组的时间。

默认值: 200

备注

注意

  • 创建目标组后,只能使用后续调用修改其运行状况检查

  • 警告: 对于模块,环境变量和配置文件是从 Ansible “主机”上下文而不是“控制器”上下文读取的。因此,可能需要将文件显式复制到“主机”。对于查找和连接插件,环境变量和配置文件是从 Ansible “控制器”上下文而不是“主机”上下文读取的。

  • Ansible 使用的 AWS SDK (boto3) 也可能从其在 Ansible “主机”上下文中的配置文件(通常是 ~/.aws/credentials)中读取凭据和其他设置(例如区域)的默认值。有关更多信息,请参阅 https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

示例

# Note: These examples do not set authentication details, see the AWS Guide for details.

- name: Create a target group with a default health check
  community.aws.elb_target_group:
    name: mytargetgroup
    protocol: http
    port: 80
    vpc_id: vpc-01234567
    state: present

- name: Create a target group with protocol_version 'GRPC'
  community.aws.elb_target_group:
    name: mytargetgroup
    protocol: http
    port: 80
    vpc_id: vpc-01234567
    protocol_version: GRPC
    state: present

- name: Modify the target group with a custom health check
  community.aws.elb_target_group:
    name: mytargetgroup
    protocol: http
    port: 80
    vpc_id: vpc-01234567
    health_check_protocol: http
    health_check_path: /health_check
    health_check_port: 80
    successful_response_codes: 200
    health_check_interval: 15
    health_check_timeout: 3
    healthy_threshold_count: 4
    unhealthy_threshold_count: 3
    state: present

- name: Delete a target group
  community.aws.elb_target_group:
    name: mytargetgroup
    state: absent

- name: Create a target group with instance targets
  community.aws.elb_target_group:
    name: mytargetgroup
    protocol: http
    port: 81
    vpc_id: vpc-01234567
    health_check_protocol: http
    health_check_path: /
    successful_response_codes: "200,250-260"
    targets:
      - Id: i-01234567
        Port: 80
      - Id: i-98765432
        Port: 80
    state: present
    wait_timeout: 200
    wait: true

- name: Create a target group with IP address targets
  community.aws.elb_target_group:
    name: mytargetgroup
    protocol: http
    port: 81
    vpc_id: vpc-01234567
    health_check_protocol: http
    health_check_path: /
    successful_response_codes: "200,250-260"
    target_type: ip
    targets:
      - Id: 10.0.0.10
        Port: 80
        AvailabilityZone: all
      - Id: 10.0.0.20
        Port: 80
    state: present
    wait_timeout: 200
    wait: true

# Using lambda as targets require that the target group
# itself is allow to invoke the lambda function.
# therefore you need first to create an empty target group
# to receive its arn, second, allow the target group
# to invoke the lambda function and third, add the target
# to the target group
- name: first, create empty target group
  community.aws.elb_target_group:
    name: my-lambda-targetgroup
    target_type: lambda
    state: present
    modify_targets: false
  register: out

- name: second, allow invoke of the lambda
  community.aws.lambda_policy:
    state: "{{ state | default('present') }}"
    function_name: my-lambda-function
    statement_id: someID
    action: lambda:InvokeFunction
    principal: elasticloadbalancing.amazonaws.com
    source_arn: "{{ out.target_group_arn }}"

- name: third, add target
  community.aws.elb_target_group:
    name: my-lambda-targetgroup
    target_type: lambda
    state: present
    targets:
      - Id: arn:aws:lambda:eu-central-1:123456789012:function:my-lambda-function

返回值

常见返回值记录在此处,以下是此模块独有的字段

描述

deregistration_connection_termination

布尔值

指示负载均衡器是否在取消注册超时结束时终止连接。

返回: 当状态为 present 时

示例: true

deregistration_delay_timeout_seconds

整数

Elastic Load Balancing 在将正在注销的目标的状态从 draining 更改为 unused 之前等待的时间。

返回: 当状态为 present 时

示例: 300

health_check_interval_seconds

整数

对单个目标进行健康检查的大概时间间隔,以秒为单位。

返回: 当状态为 present 时

示例: 30

health_check_path

字符串

运行状况检查请求的目标地址。

返回: 当状态为 present 时

示例: "/index.html"

health_check_port

字符串

用于连接目标的端口。

返回: 当状态为 present 时

示例: "traffic-port"

health_check_protocol

字符串

用于连接目标的协议。

返回: 当状态为 present 时

示例: "HTTP"

health_check_timeout_seconds

整数

在多长时间内没有响应意味着运行状况检查失败,以秒为单位。

返回: 当状态为 present 时

示例: 5

healthy_threshold_count

整数

将不健康的目标视为健康所需连续健康检查成功的次数。

返回: 当状态为 present 时

示例: 5

load_balancer_arns

list / elements=string

将流量路由到此目标组的负载均衡器的 Amazon 资源名称 (ARN)。

返回: 当状态为 present 时

示例: []

load_balancing_algorithm_type

字符串

在 community.aws 3.2.0 中添加

使用的负载均衡算法的类型。

返回: 当状态为 present 时

示例: "least_outstanding_requests"

matcher

字典

用于检查目标是否成功响应的 HTTP 代码。

返回: 当状态为 present 时

示例: {"http_code": "200"}

port

整数

目标正在侦听的端口。

返回: 当状态为 present 时

示例: 80

protocol

字符串

用于将流量路由到目标的协议。

返回: 当状态为 present 时

示例: "HTTP"

stickiness_enabled

布尔值

指示是否启用粘性会话。

返回: 当状态为 present 时

示例: true

整数

客户端请求应被路由到同一目标的时间段,以秒为单位。

返回: 当状态为 present 时

示例: 86400

stickiness_type

字符串

粘性会话的类型。

返回: 当状态为 present 时

示例: "lb_cookie"

tags

字典

附加到目标组的标签。

返回: 当状态为 present 时

示例: {"Tag": "Example"}

target_group_arn

字符串

目标组的 Amazon 资源名称 (ARN)。

返回: 当状态为 present 时

示例: "arn:aws:elasticloadbalancing:ap-southeast-2:123456789012:targetgroup/mytargetgroup/aabbccddee0044332211"

target_group_name

字符串

目标组的名称。

返回: 当状态为 present 时

示例: "mytargetgroup"

unhealthy_threshold_count

整数

在将目标视为不健康之前,需要连续进行多少次运行状况检查失败。

返回: 当状态为 present 时

示例: 2

vpc_id

字符串

目标的 VPC 的 ID。

返回: 当状态为 present 时

示例: "vpc-0123456"

作者

  • Rob White (@wimnat)