community.general.oneandone_server 模块 – 创建、销毁、启动、停止和重启 1&1 Host 服务器

注意

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

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

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

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

概要

  • 创建、销毁、更新、启动、停止和重启 1&1 Host 服务器。创建服务器时,可以选择等待服务器运行后再返回。

要求

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

  • 1and1

参数

参数

注释

api_url

字符串

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

appliance

字符串

服务器的操作系统名称或 ID。仅在状态为“present”时才需要。

auth_token

字符串

1&1 提供的 API 身份验证令牌。覆盖 ONEANDONE_AUTH_TOKEN 环境变量。

auto_increment

布尔值

一次创建多个服务器时,是否通过在主机名后追加计数来区分主机名,或者在主机名字符串中存在 %02d 或 %03d 时替换计数。

选项

  • false

  • true ← (默认)

cores_per_processor

整数

每个处理器的核心数。必须与 vcore、ram 和 hdds 参数一起提供。

count

整数

要创建的服务器数量。

默认值: 1

datacenter

字符串

数据中心位置。

选项

  • "US" ← (默认)

  • "ES"

  • "DE"

  • "GB"

description

字符串

服务器的描述。

firewall_policy

字符串

防火墙策略名称或 ID。

fixed_instance_size

字符串

服务器的实例大小名称或 ID。仅在状态为“present”时才需要,并且与 vcore、cores_per_processor、ram 和 hdds 参数互斥。

可用选项为:S, M, L, XL, XXL, 3XL, 4XL, 5XL

hdds

列表 / 元素=字典

具有嵌套“size”和“is_main”属性的硬盘列表。必须与 vcore、cores_per_processor 和 ram 参数一起提供。

hostname

字符串

服务器的主机名或 ID。仅在状态为“present”时使用。

load_balancer

字符串

负载均衡器名称或 ID。

monitoring_policy

字符串

监控策略名称或 ID。

private_network

字符串

专用网络名称或 ID。

ram

浮点数

RAM 内存大小。必须与 vcore、cores_per_processor 和 hdds 参数一起提供。

server

字符串

服务器标识符(ID 或主机名)。除“running”和“present”状态外,所有状态都需要。

server_type

字符串

要构建的服务器类型。

选项

  • "cloud" ← (默认)

  • "baremetal"

  • "k8s_node"

ssh_key

任意

用户的公钥 SSH 密钥(内容,而非路径)。

state

字符串

定义服务器的状态以创建、删除、启动或停止它。

选项

  • "present" ← (默认)

  • "absent"

  • "running"

  • "stopped"

vcore

整数

处理器的总数。必须与 cores_per_processor、ram 和 hdds 参数一起提供。

wait

布尔值

等待服务器处于“running”状态后再返回。也用于删除操作(如果不想等待每个服务器删除后再继续执行其他任务,则将其设置为“false”)。

选项

  • false

  • true ← (默认)

wait_interval

整数

使用 wait_for 方法时要等待的秒数。

默认值: 5

wait_timeout

整数

等待超时时间(秒)。

默认值: 600

属性

属性

支持

描述

check_mode

支持: 完全支持

可以在check_mode下运行,并在不修改目标的情况下返回更改状态预测。

diff_mode

支持: 不支持

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

示例

- name: Create three servers and enumerate their names
  community.general.oneandone_server:
    auth_token: oneandone_private_api_key
    hostname: node%02d
    fixed_instance_size: XL
    datacenter: US
    appliance: C5A349786169F140BCBC335675014C08
    auto_increment: true
    count: 3

- name: Create three servers, passing in an ssh_key
  community.general.oneandone_server:
    auth_token: oneandone_private_api_key
    hostname: node%02d
    vcore: 2
    cores_per_processor: 4
    ram: 8.0
    hdds:
      - size: 50
        is_main: false
    datacenter: ES
    appliance: C5A349786169F140BCBC335675014C08
    count: 3
    wait: true
    wait_timeout: 600
    wait_interval: 10
    ssh_key: SSH_PUBLIC_KEY

- name: Removing server
  community.general.oneandone_server:
    auth_token: oneandone_private_api_key
    state: absent
    server: 'node01'

- name: Starting server
  community.general.oneandone_server:
    auth_token: oneandone_private_api_key
    state: running
    server: 'node01'

- name: Stopping server
  community.general.oneandone_server:
    auth_token: oneandone_private_api_key
    state: stopped
    server: 'node01'

返回值

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

描述

servers

列表 / 元素=字符串

关于每个已处理服务器的信息

返回: 始终返回

示例: [{"hostname": "my-server", "id": "server-id"}]

作者

  • Amel Ajdinovic (@aajdinov)

  • Ethan Devenport (@edevenport)