hetzner.hcloud.ssh_key module – Create and manage ssh keys on the Hetzner Cloud.

Note

This module is part of the hetzner.hcloud collection (version 3.1.1).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install hetzner.hcloud. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: hetzner.hcloud.ssh_key.

Synopsis

  • Create, update and manage ssh keys on the Hetzner Cloud.

Aliases: hcloud_ssh_key

Requirements

The below requirements are needed on the host that executes this module.

  • python-dateutil >= 2.7.5

  • requests >=2.20

Parameters

Parameter

Comments

api_endpoint

aliases: endpoint

string

The API Endpoint for the Hetzner Cloud.

You can also set this option by using the HCLOUD_ENDPOINT environment variable.

Default: "https://api.hetzner.cloud/v1"

api_token

string / required

The API Token for the Hetzner Cloud.

You can also set this option by using the HCLOUD_TOKEN environment variable.

fingerprint

string

The Fingerprint of the Hetzner Cloud ssh_key to manage.

Only required if no ssh_key id or name is given.

id

integer

The ID of the Hetzner Cloud ssh_key to manage.

Only required if no ssh_key name is given

labels

dictionary

User-defined labels (key-value pairs)

name

string

The Name of the Hetzner Cloud ssh_key to manage.

Only required if no ssh_key id is given or a ssh_key does not exist.

public_key

string

The Public Key to add.

Required if ssh_key does not exist.

state

string

State of the ssh_key.

Choices:

  • "absent"

  • "present" ← (default)

See Also

See also

Documentation for Hetzner Cloud API

Complete reference for the Hetzner Cloud API.

Examples

- 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

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

hcloud_ssh_key

complex

The ssh_key instance

Returned: Always

fingerprint

string

Fingerprint of the ssh_key

Returned: Always

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

id

integer

ID of the ssh_key

Returned: Always

Sample: 12345

labels

dictionary

User-defined labels (key-value pairs)

Returned: Always

Sample: {"key": "value", "mylabel": 123}

name

string

Name of the ssh_key

Returned: Always

Sample: "my-ssh-key"

public_key

string

Public key of the ssh_key

Returned: Always

Sample: "ssh-rsa AAAjjk76kgf...Xt"

Authors

  • Lukas Kaemmerling (@LKaemmerling)