hetzner.hcloud.server module – Create and manage cloud servers on the Hetzner Cloud.
Note
This module is part of the hetzner.hcloud collection (version 4.2.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.server
.
Synopsis
Create, update and manage cloud servers on the Hetzner Cloud.
Aliases: hcloud_server
Requirements
The below requirements are needed on the host that executes this module.
python-dateutil >= 2.7.5
requests >=2.20
Parameters
Parameter |
Comments |
---|---|
The API Endpoint for the Hetzner Cloud. You can also set this option by using the Default: |
|
The API Token for the Hetzner Cloud. You can also set this option by using the |
|
Enable or disable Backups for the given Server. Choices:
|
|
Hetzner Cloud Datacenter (name or ID) to create the server in. Required if no Only used during the server creation. |
|
Enables the public ipv4 address. Choices:
|
|
Enables the public ipv6 address. Choices:
|
|
List of Hetzner Cloud Firewalls (name or ID) that should be attached to the server. |
|
Force the update of the server. May power off the server if update is applied. Choices:
|
|
ID of the Hetzner Cloud Server to manage. Only required if no server |
|
Hetzner Cloud Image (name or ID) to create the server from. Required if server does not exist or when |
|
Allows the creation of servers with deprecated images. Choices:
|
|
Hetzner Cloud Primary IPv4 (name or ID) to use. If omitted and |
|
Hetzner Cloud Primary IPv6 (name or ID) to use. If omitted and |
|
User-defined labels (key-value pairs). |
|
Hetzner Cloud Location (name or ID) to create the server in. Required if no Only used during the server creation. |
|
Name of the Hetzner Cloud Server to manage. Only required if no server |
|
Hetzner Cloud Placement Group (name or ID) to create the server in. |
|
List of Hetzner Cloud Networks (name or ID) the server should be attached to. If None, private networks are left as they are (e.g. if previously added by hcloud_server_network), if it has any other value (including []), only those networks are attached to the server. |
|
Add the Hetzner rescue system type you want the server to be booted into. |
|
Hetzner Cloud Server Type (name or ID) of the server. Required if server does not exist. |
|
List of Hetzner Cloud SSH Keys (name or ID) to create the server with. Only used during the server creation. |
|
State of the server. Choices:
|
|
Resize the disk size, when resizing a server. If you want to downgrade the server later, this value should be False. Choices:
|
|
User Data to be passed to the server on creation. Only used during the server creation. |
|
List of Hetzner Cloud Volumes (name or ID) that should be attached to the server. Only used during the server creation. |
See Also
See also
- Documentation for Hetzner Cloud API
Complete reference for the Hetzner Cloud API.
Examples
- name: Create a basic server
hetzner.hcloud.server:
name: my-server
server_type: cx22
image: ubuntu-22.04
state: present
- name: Create a basic server with ssh key
hetzner.hcloud.server:
name: my-server
server_type: cx22
image: ubuntu-22.04
location: fsn1
ssh_keys:
- me@myorganisation
state: present
- name: Resize an existing server
hetzner.hcloud.server:
name: my-server
server_type: cx32
upgrade_disk: true
state: present
- name: Ensure the server is absent (remove if needed)
hetzner.hcloud.server:
name: my-server
state: absent
- name: Ensure the server is started
hetzner.hcloud.server:
name: my-server
state: started
- name: Ensure the server is stopped
hetzner.hcloud.server:
name: my-server
state: stopped
- name: Ensure the server is restarted
hetzner.hcloud.server:
name: my-server
state: restarted
- name: Ensure the server is will be booted in rescue mode and therefore restarted
hetzner.hcloud.server:
name: my-server
rescue_mode: linux64
state: restarted
- name: Ensure the server is rebuild
hetzner.hcloud.server:
name: my-server
image: ubuntu-22.04
state: rebuild
- name: Add server to placement group
hetzner.hcloud.server:
name: my-server
placement_group: my-placement-group
force: true
state: present
- name: Remove server from placement group
hetzner.hcloud.server:
name: my-server
placement_group:
state: present
- name: Add server with private network only
hetzner.hcloud.server:
name: my-server
enable_ipv4: false
enable_ipv6: false
private_networks:
- my-network
- 4711
state: present
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The server instance Returned: Always |
|
Time window (UTC) in which the backup will run, or null if the backups are not enabled Returned: always Sample: |
|
Point in time when the Server was created (in ISO-8601 format) Returned: always Sample: |
|
Name of the datacenter of the server Returned: always Sample: |
|
True if server is protected for deletion Returned: always Sample: |
|
Numeric identifier of the server Returned: always Sample: |
|
Public IPv4 address of the server Returned: always Sample: |
|
IPv6 network of the server Returned: always Sample: |
|
User-defined labels (key-value pairs) Returned: always |
|
Name of the location of the server Returned: always Sample: |
|
Name of the server Returned: always Sample: |
|
Placement Group of the server Returned: always Sample: |
|
List of private networks the server is attached to (name or ID) Returned: always Sample: |
|
List of private networks the server is attached to (dict with name and ip) Returned: always Sample: |
|
True if server is protected for rebuild Returned: always Sample: |
|
True if rescue mode is enabled, Server will then boot into rescue system on next reboot Returned: always Sample: |
|
Name of the server type of the server Returned: always Sample: |
|
Status of the server Returned: always Sample: |