hetzner.hcloud.ssh_key 模块 – 在 Hetzner Cloud 上创建和管理 ssh 密钥。

注意

此模块是 hetzner.hcloud 集合(版本 4.2.2)的一部分。

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

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

要在 playbook 中使用它,请指定:hetzner.hcloud.ssh_key

概要

  • 在 Hetzner Cloud 上创建、更新和管理 ssh 密钥。

别名:hcloud_ssh_key

要求

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

  • python-dateutil >= 2.7.5

  • requests >=2.20

参数

参数

注释

api_endpoint

别名:endpoint

字符串

Hetzner Cloud 的 API 端点。

您还可以使用 HCLOUD_ENDPOINT 环境变量设置此选项。

默认值: "https://api.hetzner.cloud/v1"

api_token

字符串 / 必需

Hetzner Cloud 的 API 令牌。

您还可以使用 HCLOUD_TOKEN 环境变量设置此选项。

fingerprint

字符串

要管理的 Hetzner Cloud ssh_key 的指纹。

如果未给出 ssh_key 的 idname,则为必需。

id

整数

要管理的 Hetzner Cloud ssh_key 的 ID。

如果未给出 ssh_key 的 name,则为必需

labels

字典

用户定义的标签(键值对)

name

字符串

要管理的 Hetzner Cloud ssh_key 的名称。

如果未给出 ssh_key 的 id 或 ssh_key 不存在,则为必需。

public_key

字符串

要添加的公钥。

如果 ssh_key 不存在,则为必需。

state

字符串

ssh_key 的状态。

选项

  • "absent"

  • "present" ← (默认值)

另请参阅

另请参阅

Hetzner Cloud API 文档

Hetzner Cloud API 的完整参考。

示例

- name: Create a basic ssh_key
  hetzner.hcloud.ssh_key:
    name: my-ssh_key
    public_key: ssh-rsa AAAjjk76kgf...Xt
    state: present

- name: Create a ssh_key with labels
  hetzner.hcloud.ssh_key:
    name: my-ssh_key
    public_key: ssh-rsa AAAjjk76kgf...Xt
    labels:
      key: value
      mylabel: 123
    state: present

- name: Ensure the ssh_key is absent (remove if needed)
  hetzner.hcloud.ssh_key:
    name: my-ssh_key
    state: absent

返回值

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

描述

hcloud_ssh_key

复杂

ssh_key 实例

返回: 始终

fingerprint

字符串

ssh_key 的指纹

返回: 始终

示例: "b7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2f"

id

整数

ssh_key 的 ID

返回: 始终

示例: 12345

labels

字典

用户定义的标签(键值对)

返回: 始终

示例: {"key": "value", "mylabel": 123}

name

字符串

ssh_key 的名称

返回: 始终

示例: "my-ssh-key"

public_key

字符串

ssh_key 的公钥

返回: 始终

示例: "ssh-rsa AAAjjk76kgf...Xt"

作者

  • Lukas Kaemmerling (@LKaemmerling)