hetzner.hcloud.hcloud_server module – Create and manage cloud servers on the Hetzner Cloud.

Note

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

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.

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

Synopsis

  • Create, update and manage cloud servers on the Hetzner Cloud.

Requirements

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

  • hcloud-python >= 1.0.0

Parameters

Parameter

Comments

allow_deprecated_image

boolean

Allows the creation of servers with deprecated images.

Choices:

  • no ← (default)

  • yes

api_token

string / required

This is the API Token for the Hetzner Cloud.

backups

boolean

Enable or disable Backups for the given Server.

Choices:

  • no

  • yes

datacenter

string

Datacenter of Server.

Required of no location is given and server does not exists.

delete_protection

boolean

Protect the Server for deletion.

Needs to be the same as rebuild_protection.

Choices:

  • no

  • yes

endpoint

string

This is the API Endpoint for the Hetzner Cloud.

Default: “https://api.hetzner.cloud/v1”

firewalls

list / elements=string

List of Firewall IDs that should be attached to the server on server creation.

force

boolean

Force the update of the server.

May power off the server if update.

Choices:

  • no ← (default)

  • yes

force_upgrade

boolean

Deprecated

Force the upgrade of the server.

Power off the server if it is running on upgrade.

Choices:

  • no ← (default)

  • yes

id

integer

The ID of the Hetzner Cloud server to manage.

Only required if no server name is given

image

string

Image the server should be created from.

Required if server does not exists.

labels

dictionary

User-defined labels (key-value pairs).

location

string

Location of Server.

Required if no datacenter is given and server does not exists.

name

string

The Name of the Hetzner Cloud server to manage.

Only required if no server id is given or a server does not exists.

placement_group

string

Placement Group of the server.

rebuild_protection

boolean

Protect the Server for rebuild.

Needs to be the same as delete_protection.

Choices:

  • no

  • yes

rescue_mode

string

Add the Hetzner rescue system type you want the server to be booted into.

server_type

string

The Server Type of the Hetzner Cloud server to manage.

Required if server does not exists.

ssh_keys

list / elements=string

List of SSH key names

The key names correspond to the SSH keys configured for your Hetzner Cloud account access.

state

string

State of the server.

Choices:

  • absent

  • present ← (default)

  • restarted

  • started

  • stopped

  • rebuild

upgrade_disk

boolean

Resize the disk size, when resizing a server.

If you want to downgrade the server later, this value should be False.

Choices:

  • no ← (default)

  • yes

user_data

string

User Data to be passed to the server on creation.

Only used if server does not exists.

volumes

list / elements=string

List of Volumes IDs that should be attached to the server on server creation.

See Also

See also

Documentation for Hetzner Cloud API

Complete reference for the Hetzner Cloud API.

Examples

- name: Create a basic server
  hcloud_server:
    name: my-server
    server_type: cx11
    image: ubuntu-18.04
    state: present

- name: Create a basic server with ssh key
  hcloud_server:
    name: my-server
    server_type: cx11
    image: ubuntu-18.04
    location: fsn1
    ssh_keys:
      - me@myorganisation
    state: present

- name: Resize an existing server
  hcloud_server:
    name: my-server
    server_type: cx21
    upgrade_disk: yes
    state: present

- name: Ensure the server is absent (remove if needed)
  hcloud_server:
    name: my-server
    state: absent

- name: Ensure the server is started
  hcloud_server:
    name: my-server
    state: started

- name: Ensure the server is stopped
  hcloud_server:
    name: my-server
    state: stopped

- name: Ensure the server is restarted
  hcloud_server:
    name: my-server
    state: restarted

- name: Ensure the server is will be booted in rescue mode and therefore restarted
  hcloud_server:
    name: my-server
    rescue_mode: linux64
    state: restarted

- name: Ensure the server is rebuild
  hcloud_server:
    name: my-server
    image: ubuntu-18.04
    state: rebuild

- name: Add server to placement group
  hcloud_server:
    name: my-server
    placement_group: my-placement-group
    force: True
    state: present

- name: Remove server from placement group
  hcloud_server:
    name: my-server
    placement_group: null
    state: present

Return Values

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

Key

Description

hcloud_server

complex

The server instance

Returned: Always

backup_window

boolean

Time window (UTC) in which the backup will run, or null if the backups are not enabled

Returned: always

Sample: “22-02”

datacenter

string

Name of the datacenter of the server

Returned: always

Sample: “fsn1-dc14”

delete_protection

boolean

added in 0.1.0 of hetzner.hcloud

True if server is protected for deletion

Returned: always

Sample: false

id

integer

Numeric identifier of the server

Returned: always

Sample: 1937415

ipv4_address

string

Public IPv4 address of the server

Returned: always

Sample: “116.203.104.109”

ipv6

string

IPv6 network of the server

Returned: always

Sample: “2a01:4f8:1c1c:c140::/64”

labels

dictionary

User-defined labels (key-value pairs)

Returned: always

location

string

Name of the location of the server

Returned: always

Sample: “fsn1”

name

string

Name of the server

Returned: always

Sample: “my-server”

placement_group

string

added in 1.5.0 of hetzner.hcloud

Placement Group of the server

Returned: always

Sample: 4711

rebuild_protection

boolean

added in 0.1.0 of hetzner.hcloud

True if server is protected for rebuild

Returned: always

Sample: false

rescue_enabled

boolean

True if rescue mode is enabled, Server will then boot into rescue system on next reboot

Returned: always

Sample: false

server_type

string

Name of the server type of the server

Returned: always

Sample: “cx11”

status

string

Status of the server

Returned: always

Sample: “running”

Authors

  • Lukas Kaemmerling (@LKaemmerling)