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
参数
参数 |
注释 |
---|---|
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 和 profile 选项是互斥的。 为了与 AWS botocore SDK 保持一致,在版本 5.1.0 中添加了 aws_access_key_id 别名。 ec2_access_key 别名已被弃用,将在 2024-12-01 之后的版本中删除。 对 |
|
用于验证 SSL 证书的 CA 包的位置。 也可以使用 |
|
用于修改 botocore 配置的字典。 可以在 AWS 文档中找到参数 https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config。 |
|
使用 也可以使用 选项
|
|
指示负载均衡器是否在取消注册超时结束时终止连接。 仅当附加到网络负载均衡器 (NLB) 时才支持使用此选项。 选项
|
|
弹性负载均衡在将取消注册目标的的状态从 draining 更改为 unused 之前等待的时间。范围是 0-3600 秒。 |
|
要连接的 URL,而不是默认的 AWS 端点。虽然这可以用于连接到其他 AWS 兼容服务,但 amazon.aws 和 community.aws 集合仅针对 AWS 进行了测试。 可以使用 ec2_url 和 s3_url 别名已被弃用,将在 2024-12-01 之后的版本中移除。 对 |
|
对单个目标进行健康检查的大概时间间隔,以秒为单位。 |
|
作为健康检查目标的 ping 路径。必须定义此路径才能设置健康检查。 需要设置 health_check_protocol 参数。 |
|
负载均衡器在对目标执行健康检查时使用的端口。可以设置为“traffic-port”以匹配目标端口。 如果未定义,则默认为每个目标从负载均衡器接收流量的端口。 |
|
负载均衡器在对目标执行健康检查时使用的协议。 选项
|
|
在多少秒内,如果目标没有响应则表示健康检查失败。 |
|
将不健康的目标视为健康所需连续健康检查成功的次数。 |
|
要使用的负载均衡算法的类型。 仅当与应用程序负载均衡器 (ALB) 一起使用时,才支持更改负载均衡算法。 如果未设置,AWS 将默认为 选项
|
|
是否更改组中现有的目标以匹配模块传递的内容 选项
|
|
目标组的名称。 |
|
目标接收流量的端口。除非在注册目标时指定端口覆盖,否则将使用此端口。 当 state 为 |
|
指示是否启用客户端 IP 保留。 如果目标组类型为 preserve_client_ip_enabled 仅受网络负载均衡器支持。 选项
|
|
用于身份验证的命名 AWS 配置文件。 有关命名配置文件的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html。 也可以使用 profile 选项与 aws_access_key、aws_secret_key 和 security_token 选项互斥。 |
|
用于将流量路由到目标的协议。 当 state 为 选项
|
|
指定协议版本。 protocol_version 参数是不可变的,并且在更新 elb_target_group 时无法更改。 选项
|
|
指示是否启用代理协议版本 2。 该值为 proxy_protocol_v2_enabled 仅受网络负载均衡器支持。 选项
|
|
如果 如果未设置 以 选项
|
|
要使用的 AWS 区域。 对于 IAM、Route53 和 CloudFront 等全局服务,将忽略 region。 可以使用 有关更多信息,请参阅 Amazon AWS 文档 http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region。
对 |
|
AWS 私有访问密钥。 有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys。 也可以使用 secret_key 和 profile 选项互斥。 为了与 AWS botocore SDK 保持一致,在 5.1.0 版本中添加了 aws_secret_access_key 别名。 ec2_secret_key 别名已被弃用,将在 2024-12-01 之后的版本中移除。 对 |
|
用于临时凭证的 AWS STS 会话令牌。 有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys。 也可以使用 security_token 和 profile 选项互斥。 在 3.2.0 版本中添加了别名 aws_session_token 和 session_token,该参数在 6.0.0 版本中从 security_token 重命名为 session_token。 security_token、aws_security_token 和 access_token 别名已被弃用,将在 2024-12-01 之后的版本中移除。 对 |
|
创建或销毁目标组。 选项
|
|
客户端请求应路由到同一目标的时间段(以秒为单位)。在此时间段到期后,应用程序生成的 Cookie 将被视为过期。范围为 1 秒到 1 周(604800 秒)。 |
|
应用程序 Cookie 的名称。如果 stickiness_type=app_cookie,则为必填项。 |
|
指示是否启用粘性会话。 选项
|
|
客户端请求应被路由到同一目标的时间段,以秒为单位。在此时间段到期后,负载均衡器生成的 Cookie 将被视为过期。范围为 1 秒到 1 周(604800 秒)。 |
|
粘性会话的类型。 有效值为 如果未设置,对于应用程序负载均衡器,AWS 将默认为 |
|
用于检查目标是否成功响应的 HTTP 代码。 接受多个值(例如,“200,202”)或值范围(例如,“200-299”)。 需要设置 health_check_protocol 参数。 |
|
一个表示要应用于资源的标签的字典。 如果未设置 |
|
向此目标组注册目标时必须指定的目标类型。可能的值为 默认行为是 选项
|
|
要分配给目标组的目标列表。此参数默认为空列表。除非您设置了“modify_targets”参数,否则所有现有目标都将从该组中删除。该列表应包含 Id 和 Port 参数。有关详细信息,请参阅示例。 |
|
在将目标视为不健康之前,需要连续进行多少次运行状况检查失败。 |
|
设置为 强烈建议不要设置 validate_certs=false ,作为替代方案,请考虑设置 aws_ca_bundle 。 选项
|
|
虚拟私有云 (VPC) 的标识符。 当 state 为 |
|
是否等待目标组。 选项
|
|
等待目标组的时间。 默认值: |
备注
注意
创建目标组后,只能使用后续调用修改其运行状况检查
警告: 对于模块,环境变量和配置文件是从 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
返回值
常见返回值记录在此处,以下是此模块独有的字段
键 |
描述 |
---|---|
指示负载均衡器是否在取消注册超时结束时终止连接。 返回: 当状态为 present 时 示例: |
|
Elastic Load Balancing 在将正在注销的目标的状态从 draining 更改为 unused 之前等待的时间。 返回: 当状态为 present 时 示例: |
|
对单个目标进行健康检查的大概时间间隔,以秒为单位。 返回: 当状态为 present 时 示例: |
|
运行状况检查请求的目标地址。 返回: 当状态为 present 时 示例: |
|
用于连接目标的端口。 返回: 当状态为 present 时 示例: |
|
用于连接目标的协议。 返回: 当状态为 present 时 示例: |
|
在多长时间内没有响应意味着运行状况检查失败,以秒为单位。 返回: 当状态为 present 时 示例: |
|
将不健康的目标视为健康所需连续健康检查成功的次数。 返回: 当状态为 present 时 示例: |
|
将流量路由到此目标组的负载均衡器的 Amazon 资源名称 (ARN)。 返回: 当状态为 present 时 示例: |
|
使用的负载均衡算法的类型。 返回: 当状态为 present 时 示例: |
|
用于检查目标是否成功响应的 HTTP 代码。 返回: 当状态为 present 时 示例: |
|
目标正在侦听的端口。 返回: 当状态为 present 时 示例: |
|
用于将流量路由到目标的协议。 返回: 当状态为 present 时 示例: |
|
指示是否启用粘性会话。 返回: 当状态为 present 时 示例: |
|
客户端请求应被路由到同一目标的时间段,以秒为单位。 返回: 当状态为 present 时 示例: |
|
粘性会话的类型。 返回: 当状态为 present 时 示例: |
|
附加到目标组的标签。 返回: 当状态为 present 时 示例: |
|
目标组的 Amazon 资源名称 (ARN)。 返回: 当状态为 present 时 示例: |
|
目标组的名称。 返回: 当状态为 present 时 示例: |
|
在将目标视为不健康之前,需要连续进行多少次运行状况检查失败。 返回: 当状态为 present 时 示例: |
|
目标的 VPC 的 ID。 返回: 当状态为 present 时 示例: |