community.general.oneandone_load_balancer 模块 – 配置 1&1 负载均衡器

注意

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

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

要安装它,请使用:ansible-galaxy collection install community.general。 您需要进一步的要求才能使用此模块,请参阅 要求 了解详细信息。

要在 playbook 中使用它,请指定:community.general.oneandone_load_balancer

概要

  • 创建、删除、更新负载均衡器。 此模块依赖于 1and1 >= 1.0。

要求

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

  • 1and1

参数

参数

注释

add_rules

列表 / 元素=字典

要添加到现有负载均衡器的规则列表。 它的语法与 rules 参数使用的语法相同。 与 update 状态结合使用。

默认值: []

add_server_ips

列表 / 元素=字符串

要分配给负载均衡器的服务器标识符(ID 或名称)列表。 与 update 状态结合使用。

默认值: []

api_url

字符串

自定义 API URL。 覆盖 ONEANDONE_API_URL 环境变量。

auth_token

字符串

由 1&1 提供的身份验证 API 令牌。

datacenter

字符串

将创建负载均衡器的数据中心的 ID 或国家/地区代码。

如果未指定,则默认为 US

选项

  • "US"

  • "ES"

  • "DE"

  • "GB"

description

字符串

负载均衡器的描述。 maxLength=256

health_check_interval

字符串

运行状况检查周期(以秒为单位)。 minimum=5, maximum=300, multipleOf=1

health_check_parse

字符串

要检查的正则表达式。 HTTP 运行状况检查是必需的。 maxLength=64

health_check_path

字符串

要调用的检查 URL。 HTTP 运行状况检查是必需的。 maxLength=1000

health_check_test

字符串

运行状况检查的类型。 目前不允许使用 HTTP。

选项

  • "NONE"

  • "TCP"

  • "HTTP"

  • "ICMP"

load_balancer

字符串

与 update 状态一起使用的负载均衡器的标识符(ID 或名称)。

method

字符串

负载均衡程序。

选项

  • "ROUND_ROBIN"

  • "LEAST_CONNECTIONS"

name

字符串

与 present 状态一起使用的负载均衡器名称。 与 absent 状态一起使用时用作标识符(ID 或名称)。 maxLength=128

persistence

布尔值

持久性。

选项

  • false

  • true

persistence_time

字符串

持久性时间(以秒为单位)。 如果启用了持久性,则为必需项。 minimum=30, maximum=1200, multipleOf=1

remove_rules

列表 / 元素=字符串

将从现有负载均衡器中删除的规则 ID 列表。 与 update 状态结合使用。

默认值: []

remove_server_ips

列表 / 元素=字符串

要从负载均衡器中取消分配的服务器 IP ID 列表。 与 update 状态结合使用。

默认值: []

rules

列表 / 元素=字典

将为负载均衡器设置的规则对象列表。 除了可选的 source 参数外,每个规则都必须包含 protocol、port_balancer 和 port_server 参数。

默认值: []

state

字符串

定义要创建、删除或更新的负载均衡器状态。

选项

  • "present" ← (默认)

  • "absent"

  • "update"

wait

布尔值

在返回之前等待实例处于“正在运行”状态

选项

  • false

  • true ← (默认)

wait_interval

整数

定义在使用 _wait_for 方法时要等待的秒数

默认值: 5

wait_timeout

整数

等待放弃前的等待时间,以秒为单位

默认值: 600

属性

属性

支持

描述

check_mode

支持:完全

可以在 check_mode 中运行,并返回更改状态预测,而无需修改目标。

diff_mode

支持:

在差异模式下,将返回有关已更改(或可能需要在 check_mode 中更改)的详细信息。

示例

- name: Create a load balancer
  community.general.oneandone_load_balancer:
    auth_token: oneandone_private_api_key
    name: ansible load balancer
    description: Testing creation of load balancer with ansible
    health_check_test: TCP
    health_check_interval: 40
    persistence: true
    persistence_time: 1200
    method: ROUND_ROBIN
    datacenter: US
    rules:
     -
       protocol: TCP
       port_balancer: 80
       port_server: 80
       source: 0.0.0.0
    wait: true
    wait_timeout: 500

- name: Destroy a load balancer
  community.general.oneandone_load_balancer:
    auth_token: oneandone_private_api_key
    name: ansible load balancer
    wait: true
    wait_timeout: 500
    state: absent

- name: Update a load balancer
  community.general.oneandone_load_balancer:
    auth_token: oneandone_private_api_key
    load_balancer: ansible load balancer
    name: ansible load balancer updated
    description: Testing the update of a load balancer with ansible
    wait: true
    wait_timeout: 500
    state: update

- name: Add server to a load balancer
  community.general.oneandone_load_balancer:
    auth_token: oneandone_private_api_key
    load_balancer: ansible load balancer updated
    description: Adding server to a load balancer with ansible
    add_server_ips:
     - server identifier (id or name)
    wait: true
    wait_timeout: 500
    state: update

- name: Remove server from a load balancer
  community.general.oneandone_load_balancer:
    auth_token: oneandone_private_api_key
    load_balancer: ansible load balancer updated
    description: Removing server from a load balancer with ansible
    remove_server_ips:
     - B2504878540DBC5F7634EB00A07C1EBD (server's ip id)
    wait: true
    wait_timeout: 500
    state: update

- name: Add rules to a load balancer
  community.general.oneandone_load_balancer:
    auth_token: oneandone_private_api_key
    load_balancer: ansible load balancer updated
    description: Adding rules to a load balancer with ansible
    add_rules:
     -
       protocol: TCP
       port_balancer: 70
       port_server: 70
       source: 0.0.0.0
     -
       protocol: TCP
       port_balancer: 60
       port_server: 60
       source: 0.0.0.0
    wait: true
    wait_timeout: 500
    state: update

- name: Remove rules from a load balancer
  community.general.oneandone_load_balancer:
    auth_token: oneandone_private_api_key
    load_balancer: ansible load balancer updated
    description: Adding rules to a load balancer with ansible
    remove_rules:
     - rule_id #1
     - rule_id #2
     - ...
    wait: true
    wait_timeout: 500
    state: update

返回值

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

描述

load_balancer

字典

关于已处理的负载均衡器的信息

返回: 始终

示例: {"id": "92B74394A397ECC3359825C1656D67A6", "name": "默认 负载均衡器"}

作者

  • Amel Ajdinovic (@aajdinov)

  • Ethan Devenport (@edevenport)