community.aws.elb_network_lb 模块 – 管理网络负载均衡器
注意
此模块是 community.aws 集合(版本 9.0.0)的一部分。
如果您使用的是 ansible 包,您可能已经安装了此集合。 它不包含在 ansible-core 中。 要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.aws。 您需要满足其他要求才能使用此模块,有关详细信息,请参阅要求。
要在剧本中使用它,请指定:community.aws.elb_network_lb。
community.aws 1.0.0 中的新功能
概要
- 管理 AWS 网络弹性负载均衡器。 有关详细信息,请参阅 https://aws.amazon.com/blogs/aws/new-network-load-balancer-effortless-scaling-to-millions-of-requests-per-second/。 
要求
执行此模块的主机需要满足以下要求。
- 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。 | |
| 指示是否启用跨区域负载均衡。 默认为  选项 
 | |
| 使用  也可以使用  选项 
 | |
| 指示是否启用了 ELB 的删除保护。 默认为  选项 
 | |
| 要连接到的 URL,而不是默认的 AWS 终端节点。 虽然这可以用于连接到其他与 AWS 兼容的服务,但 amazon.aws 和 community.aws 集合仅针对 AWS 进行测试。 也可以按优先级降序使用  ec2_url 和 s3_url 别名已弃用,将在 2024-12-01 之后的版本中删除。 已弃用对  | |
| 设置指定应用程序负载均衡器的子网使用的 IP 地址类型。 选项 
 | |
| 包含要附加到 ELB 的侦听器的字典列表。 有关所需字典的详细信息,请参见示例。请注意,侦听器键是驼峰式命名的。 | |
| 应用程序层协议协商 (ALPN) 策略的名称。 选项 
 | |
| SSL 服务器证书。 | |
| 证书的 Amazon 资源名称 (ARN)。 | |
| 侦听器的默认操作。 | |
| 目标组的 Amazon 资源名称 (ARN)。 与 TargetGroupName 互斥。 | |
| 目标组的名称。 与 TargetGroupArn 互斥。 | |
| 操作的类型。 | |
| 负载均衡器正在侦听的端口。 | |
| 从客户端到负载均衡器的连接的协议。 | |
| 定义支持的密码和协议的安全策略。 | |
| 负载均衡器的名称。此名称在您的 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 选项互斥。 | |
| 如果 purge_listeners=true,则将从 ELB 中清除现有侦听器,以完全匹配 listeners 参数定义的侦听器。 如果未设置 listeners 参数,则不会修改侦听器。 选项 
 | |
| 如果  如果未设置  以  选项 
 | |
| 要使用的 AWS 区域。 对于 IAM、Route53 和 CloudFront 等全局服务,将忽略 region。 也可以使用  有关更多信息,请参阅 Amazon AWS 文档 http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region。 
 已弃用对  | |
| 面向 Internet 或内部的负载均衡器。ELB 方案在创建后无法修改。 选项 
 | |
| 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 之后的版本中删除。 已弃用对  | |
| 创建或销毁负载均衡器。 默认值在 4.0.0 版本中从  选项 
 | |
| 包含要附加到负载均衡器的子网 ID 的字典列表。您还可以指定要附加到负载均衡器的弹性 IP 的分配 ID 或内部负载均衡器的内部 IP 地址。每个子网可以指定一个弹性 IP 地址或内部地址。 此参数与 subnets 互斥。 | |
| 要附加到负载均衡器的子网 ID 列表。 每个可用区只能指定一个子网。您必须指定至少来自两个可用区的子网。 当 state=present 时是必需的。 此参数与 subnet_mappings 互斥。 | |
| 表示要应用于资源的标签的字典。 如果未设置  | |
| 设置为  强烈建议不要将 validate_certs=false,作为替代方案,请考虑设置 aws_ca_bundle。 选项 
 | |
| 是否等待网络负载均衡器达到所需状态。 选项 
 | |
| 等待的持续时间(以秒为单位),与 wait 结合使用。 | 
注释
注意
- 侦听器根据端口进行匹配。如果更改了侦听器的端口,则将创建一个新的侦听器。 
- 侦听器规则根据优先级进行匹配。如果更改了规则的优先级,则将创建一个新的规则。 
- 注意:对于模块,环境变量和配置文件是从 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 an ELB and attach a listener
  community.aws.elb_network_lb:
    name: myelb
    subnets:
      - subnet-012345678
      - subnet-abcdef000
    listeners:
      - Protocol: TCP # Required. The protocol for connections from clients to the load balancer (TCP, TLS, UDP or TCP_UDP) (case-sensitive).
        Port: 80 # Required. The port on which the load balancer is listening.
        DefaultActions:
          - Type: forward # Required. Only 'forward' is accepted at this time
            TargetGroupName: mytargetgroup # Required. The name of the target group
    state: present
- name: Create an ELB with an attached Elastic IP address
  community.aws.elb_network_lb:
    name: myelb
    subnet_mappings:
      - SubnetId: subnet-012345678
        AllocationId: eipalloc-aabbccdd
    listeners:
      - Protocol: TCP # Required. The protocol for connections from clients to the load balancer (TCP, TLS, UDP or TCP_UDP) (case-sensitive).
        Port: 80 # Required. The port on which the load balancer is listening.
        DefaultActions:
          - Type: forward # Required. Only 'forward' is accepted at this time
            TargetGroupName: mytargetgroup # Required. The name of the target group
    state: present
- name: Create an internal ELB with a specified IP address
  community.aws.elb_network_lb:
    name: myelb
    scheme: internal
    subnet_mappings:
      - SubnetId: subnet-012345678
        PrivateIPv4Address: 192.168.0.1 # Must be an address from within the CIDR of the subnet.
    listeners:
      - Protocol: TCP # Required. The protocol for connections from clients to the load balancer (TCP, TLS, UDP or TCP_UDP) (case-sensitive).
        Port: 80 # Required. The port on which the load balancer is listening.
        DefaultActions:
          - Type: forward # Required. Only 'forward' is accepted at this time
            TargetGroupName: mytargetgroup # Required. The name of the target group
    state: present
- name: Remove an ELB
  community.aws.elb_network_lb:
    name: myelb
    state: absent
返回值
常见的返回值记录在此处,以下是此模块特有的字段
| Key | 描述 | 
|---|---|
| 网络负载均衡器的表示 返回: 当状态为 present 时 | |
| 负载均衡器的可用区。 返回: 当状态为 present 时 示例:  | |
| 与负载均衡器关联的 Amazon Route 53 托管区域的 ID。 返回: 当状态为 present 时 示例:  | |
| 创建负载均衡器的日期和时间。 返回: 当状态为 present 时 示例:  | |
| 指示是否启用了删除保护。 返回: 当状态为 present 时 示例:  | |
| 负载均衡器的公共 DNS 名称。 返回: 当状态为 present 时 示例:  | |
| 空闲超时值,以秒为单位。 返回: 当状态为 present 时 示例:  | |
| 负载均衡器的子网使用的 IP 地址类型。 返回: 当状态为 present 时 示例:  | |
| 关于监听器的信息。 返回: 当状态为 present 时 | |
| 应用程序层协议协商 (ALPN) 策略的名称。 返回: 当状态为 present 时 示例:  | |
| SSL 服务器证书。 返回: 当状态为 present 时 | |
| 证书的 Amazon 资源名称 (ARN)。 返回: 当状态为 present 时 示例:  | |
| 侦听器的默认操作。 返回: 当状态为 present 时 | |
| 目标组的 Amazon 资源名称 (ARN)。 返回: 当状态为 present 时 示例:  | |
| 操作的类型。 返回: 当状态为 present 时 示例:  | |
| 监听器的 Amazon 资源名称 (ARN)。 返回: 当状态为 present 时 示例:  | |
| 负载均衡器的 Amazon 资源名称 (ARN)。 返回: 当状态为 present 时 示例:  | |
| 负载均衡器正在侦听的端口。 返回: 当状态为 present 时 示例:  | |
| 从客户端到负载均衡器的连接的协议。 返回: 当状态为 present 时 示例:  | |
| 定义支持的密码和协议的安全策略。 返回: 当状态为 present 时 示例:  | |
| 负载均衡器的 Amazon 资源名称 (ARN)。 返回: 当状态为 present 时 示例:  | |
| 负载均衡器的名称。 返回: 当状态为 present 时 示例:  | |
| 指示是否启用跨区域负载均衡。 返回: 当状态为 present 时 示例:  | |
| 面向 Internet 或内部负载均衡器。 返回: 当状态为 present 时 示例:  | |
| 负载均衡器的状态。 返回: 当状态为 present 时 示例:  | |
| 附加到负载均衡器的标签。 返回: 当状态为 present 时 示例:  | |
| 负载均衡器的类型。 返回: 当状态为 present 时 示例:  | |
| 负载均衡器的 VPC ID。 返回: 当状态为 present 时 示例:  | 
