amazon.aws.elb_application_lb 模块 – 管理应用程序负载均衡器
注意
此模块是 amazon.aws 集合(版本 9.0.0)的一部分。
如果您使用的是 ansible
包,您可能已经安装了此集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install amazon.aws
。您需要进一步的要求才能使用此模块,请参阅 要求了解详细信息。
要在 playbook 中使用它,请指定:amazon.aws.elb_application_lb
。
amazon.aws 5.0.0 中的新增功能
概要
管理 AWS 应用程序弹性负载均衡器。有关详细信息,请参阅 https://aws.amazon.com/blogs/aws/new-aws-application-load-balancer/。
此模块最初在 1.0.0 版本中添加到
community.aws
。
要求
执行此模块的主机需要满足以下要求。
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 之后的版本中删除。 对 |
|
访问日志的 S3 存储桶的名称。 存储桶必须与负载均衡器位于同一区域,并且具有授予 Elastic Load Balancing 写入存储桶权限的存储桶策略。 如果启用了 Amazon S3 中的访问日志,则为必需。 设置后,还必须设置 |
|
S3 存储桶中日志位置的前缀。 如果未指定前缀,则访问日志将存储在存储桶的根目录中。 不能以斜杠开头或结尾。 |
|
用于验证 SSL 证书的 CA 包的位置。 也可以使用 |
|
用于修改 botocore 配置的字典。 可以在 AWS 文档中找到参数 https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config。 |
|
使用 也可以使用 选择
|
|
指示是否启用了 ALB 的删除保护。 默认为 选择
|
|
连接到 URL 而不是默认的 AWS 端点。虽然这可以用于连接到其他与 AWS 兼容的服务,但 amazon.aws 和 community.aws 集合仅针对 AWS 进行了测试。 也可以使用 ec2_url 和 s3_url 别名已被弃用,将在 2024-12-01 之后的版本中移除。 对 |
|
指示是否启用 HTTP2 路由。 默认为 选择
|
|
确定负载均衡器如何处理可能对应用程序构成安全风险的请求。 默认为 选择
|
|
指示负载均衡器是删除带有无效标头字段的 HTTP 标头 ( 默认为 选择
|
|
指示在将客户端请求发送到目标之前,是否将这两个标头添加到客户端请求中。 默认为 选择
|
|
指示 X-Forwarded-For 标头是否应保留客户端用于连接到负载均衡器的源端口。 默认为 选择
|
|
空闲连接关闭前等待的秒数。 |
|
设置指定应用程序负载均衡器的子网使用的 IP 地址类型。 选择
|
|
包含要附加到 ALB 的侦听器的字典列表。有关所需字典的详细信息,请参见示例。请注意,侦听器键采用驼峰式命名。 |
|
SSL 服务器证书。 |
|
证书的 Amazon 资源名称 (ARN)。 |
|
侦听器的默认操作。 |
|
目标组的 Amazon 资源名称 (ARN)。 |
|
目标组的名称。 |
|
操作的类型。 |
|
负载均衡器正在侦听的端口。 |
|
从客户端到负载均衡器的连接的协议。 |
|
ALB 侦听器规则列表。 有关可能的条件和操作的完整文档,请参见 boto3 文档 请记住,AWS 对未请求的参数使用默认值。例如,当操作类型为 |
|
如果满足所有规则的条件,则应用的操作。 |
|
必须满足才能应用操作的条件。 |
|
规则优先级。 |
|
定义支持哪些密码和协议的安全策略。 |
|
负载均衡器的名称。此名称在您的 AWS 账户中必须是唯一的,最多可以包含 32 个字符,必须仅包含字母数字字符或连字符,并且不能以连字符开头或结尾。 |
|
用于身份验证的命名 AWS 配置文件。 有关命名配置文件的更多信息,请参见 AWS 文档 https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html。 也可以使用 profile 选项与 aws_access_key、aws_secret_key 和 security_token 选项互斥。 |
|
设置为 选择
|
|
如果 如果未设置 以 选择
|
|
要使用的 AWS 区域。 对于 IAM、Route53 和 CloudFront 等全局服务,将忽略 region。 也可以使用 有关更多信息,请参见 Amazon AWS 文档 http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region。
对 |
|
面向互联网的或内部负载均衡器。ALB 方案在创建后无法修改。 选择
|
|
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 选项是互斥的。 别名 aws_session_token 和 session_token 在 3.2.0 版本中添加,参数在 6.0.0 版本中从 security_token 重命名为 session_token。 别名 security_token、aws_security_token 和 access_token 已被弃用,将在 2024-12-01 之后的版本中删除。 对 |
|
创建或销毁负载均衡器。 选择
|
|
要附加到负载均衡器的子网 ID 列表。每个可用区只能指定一个子网。必须指定来自至少两个可用区的子网。 如果 |
|
表示要应用于资源的标签的字典。 如果未设置 |
|
设置为 强烈建议不要设置 validate_certs=false,作为替代方案,请考虑设置 aws_ca_bundle。 选择
|
|
指示是否允许启用了 AWS WAF 的负载均衡器在无法将请求转发到 AWS WAF 时,将请求路由到目标。 默认为 选择
|
|
在完成之前,等待负载均衡器的状态变为“active”。每 15 秒执行一次状态检查,直到达到成功状态。在 40 次检查失败后返回错误。 选择
|
|
与 |
注释
注意
侦听器根据端口进行匹配。如果侦听器的端口发生更改,则将创建一个新的侦听器。
侦听器规则根据优先级进行匹配。如果规则的优先级发生更改,则将创建一个新的规则。
注意: 对于模块,环境变量和配置文件是从 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.
# Create an ALB and attach a listener
- amazon.aws.elb_application_lb:
name: myalb
security_groups:
- sg-12345678
- my-sec-group
subnets:
- subnet-012345678
- subnet-abcdef000
listeners:
- Protocol: HTTP # Required. The protocol for connections from clients to the load balancer (HTTP or HTTPS) (case-sensitive).
Port: 80 # Required. The port on which the load balancer is listening.
# The security policy that defines which ciphers and protocols are supported. The default is the current predefined security policy.
SslPolicy: ELBSecurityPolicy-2015-05
Certificates: # The ARN of the certificate
- CertificateArn: arn:aws:iam::123456789012:server-certificate/test.domain.com
DefaultActions:
- Type: forward # Required.
TargetGroupName: # Required. The name of the target group
state: present
# Create an ALB and attach a listener with logging enabled
- amazon.aws.elb_application_lb:
access_logs_enabled: true
access_logs_s3_bucket: mybucket
access_logs_s3_prefix: "logs"
name: myalb
security_groups:
- sg-12345678
- my-sec-group
subnets:
- subnet-012345678
- subnet-abcdef000
listeners:
- Protocol: HTTP # Required. The protocol for connections from clients to the load balancer (HTTP or HTTPS) (case-sensitive).
Port: 80 # Required. The port on which the load balancer is listening.
# The security policy that defines which ciphers and protocols are supported. The default is the current predefined security policy.
SslPolicy: ELBSecurityPolicy-2015-05
Certificates: # The ARN of the certificate
- CertificateArn: arn:aws:iam::123456789012:server-certificate/test.domain.com
DefaultActions:
- Type: forward # Required.
TargetGroupName: # Required. The name of the target group
state: present
# Create an ALB with listeners and rules
- amazon.aws.elb_application_lb:
name: test-alb
subnets:
- subnet-12345678
- subnet-87654321
security_groups:
- sg-12345678
scheme: internal
listeners:
- Protocol: HTTPS
Port: 443
DefaultActions:
- Type: forward
TargetGroupName: test-target-group
Certificates:
- CertificateArn: arn:aws:iam::123456789012:server-certificate/test.domain.com
SslPolicy: ELBSecurityPolicy-2015-05
Rules:
- Conditions:
- Field: path-pattern
Values:
- '/test'
Priority: '1'
Actions:
- TargetGroupName: test-target-group
Type: forward
- Conditions:
- Field: path-pattern
Values:
- "/redirect-path/*"
Priority: '2'
Actions:
- Type: redirect
RedirectConfig:
Host: "#{host}"
Path: "/example/redir" # or /#{path}
Port: "#{port}"
Protocol: "#{protocol}"
Query: "#{query}"
StatusCode: "HTTP_302" # or HTTP_301
- Conditions:
- Field: path-pattern
Values:
- "/fixed-response-path/"
Priority: '3'
Actions:
- Type: fixed-response
FixedResponseConfig:
ContentType: "text/plain"
MessageBody: "This is the page you're looking for"
StatusCode: "200"
- Conditions:
- Field: host-header
Values:
- "hostname.domain.com"
- "alternate.domain.com"
Priority: '4'
Actions:
- TargetGroupName: test-target-group
Type: forward
state: present
# Create an ALB with a listener having multiple listener certificates
- amazon.aws.elb_application_lb:
name: myalb
security_groups:
- sg-12345678
- my-sec-group
subnets:
- subnet-012345678
- subnet-abcdef000
listeners:
- Protocol: HTTP # Required. The protocol for connections from clients to the load balancer (HTTP or HTTPS) (case-sensitive).
Port: 80 # Required. The port on which the load balancer is listening.
# The security policy that defines which ciphers and protocols are supported. The default is the current predefined security policy.
SslPolicy: ELBSecurityPolicy-2015-05
Certificates: # The ARN of the certificate (first certificate in the list will be set as default certificate)
- CertificateArn: arn:aws:iam::123456789012:server-certificate/test.domain.com
- CertificateArn: arn:aws:iam::123456789012:server-certificate/secondtest.domain.com
- CertificateArn: arn:aws:iam::123456789012:server-certificate/thirdtest.domain.com
DefaultActions:
- Type: forward # Required.
TargetGroupName: # Required. The name of the target group
state: present
# Remove an ALB
- amazon.aws.elb_application_lb:
name: myalb
state: absent
返回值
常见返回值记录在此处,以下是此模块独有的字段
键 |
描述 |
---|---|
负载均衡器的可用区。 返回: 当 示例: |
|
有关负载均衡器的静态 IP 地址的信息。 返回: 当 |
|
面向内部的负载均衡器的弹性 IP 地址的分配 ID。 返回: 当 |
|
静态 IP 地址。 返回: 当 |
|
IPv6 地址。 返回: 当 |
|
内部负载均衡器的私有 IPv4 地址。 返回: 当 |
|
子网的 ID。 返回: 当 |
|
可用区的名称。 返回: 当 |
|
是否创建/更新/删除了 ALB。 返回: 总是 示例: |
|
负载均衡器的公共 DNS 名称。 返回: 当 示例: |
|
有关侦听器的信息。 返回: 当 |
|
SSL 服务器证书。 返回: 当 |
|
证书的 Amazon 资源名称 (ARN)。 返回: 当 示例: |
|
侦听器的默认操作。 返回: 当 示例: |
|
用于创建在多个目标组之间分配请求的操作的信息。 返回: 当 |
|
规则的目标组粘性。 返回: 当 |
|
指示是否启用了目标组粘性。 返回: 当 |
|
目标组。 返回: 当 |
|
目标组的 Amazon 资源名称 (ARN)。 返回: 当 |
|
权重。 返回: 当 |
|
目标组的 Amazon 资源名称 (ARN)。 返回: 当 示例: |
|
侦听器的 Amazon 资源名称 (ARN)。 返回: 当 示例: |
|
负载均衡器的 Amazon 资源名称 (ARN)。 返回: 当 示例: |
|
侦听器规则列表。 返回: 当 |
|
操作。 返回: 当 示例: |
|
用于创建在多个目标组之间分配请求的操作的信息。 返回: 当 |
|
规则的目标组粘性。 返回: 当 |
|
指示是否启用了目标组粘性。 返回: 当 |
|
目标组。 返回: 当 |
|
目标组的 Amazon 资源名称 (ARN)。 返回: 当 |
|
权重。 返回: 当 |
|
目标组的 Amazon 资源名称 (ARN)。 返回: 当 |
|
操作的类型。 返回: 当 |
|
负载均衡器的 Amazon 资源名称 (ARN)。 返回: 当 示例: |
|
状态代码。 返回:成功 |
|
状态的描述。 返回:可用时 |
|