Deploy a Minecraft PaperMC server on Hetzner using Terraform and Ansible.
The Minecraft server is deployed as a container and using GeyserMC and Floodgate, Minecraft Bedrock Edition players can also play on the Java edition server. Optionally, you can also deploy a container to backup the Minecraft server world.
The default server deployed is cx21
. See Hetzner Cloud for the full list of available server types.
minecraft_image_tag: latest
The itzg/minecraft-server container image tag to use. See itzg/minecraft-server/tags for more available tags.
minecraft_geysermc_download_url: https://ci.opencollab.dev/job/GeyserMC/job/Geyser/job/master/lastSuccessfulBuild/artifact/bootstrap/spigot/target/Geyser-Spigot.jar
minecraft_floodgate_download_url: https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/master/lastSuccessfulBuild/artifact/spigot/build/libs/floodgate-spigot.jar
The download URLs for the GeyserMC and Floodgate plugins. These plugins allow Minecraft Bedrock Edition players to play on a Java edition server.
# All container environment variables can be found at: https://github.com/itzg/docker-minecraft-server#server-configuration
minecraft_options:
# ...
# Modify the below variables
# https://github.com/itzg/docker-minecraft-server#memory-limit
MEMORY: 2500M
# https://github.com/itzg/docker-minecraft-server#versions
VERSION: LATEST
# https://github.com/itzg/docker-minecraft-server#downloadable-world
WORLD: http://www.example.com/worlds/MySave.zip
# https://github.com/itzg/docker-minecraft-server#server-configuration
MOTD: A Minecraft Server created using https://github.com/dbrennand/mc-hetzner
# ...
The environment variables passed to the itzg/minecraft-server container. These environment variables configure the Minecraft server.
minecraft_backup: false
Whether or not to deploy the itzg/mc-backup container image to backup the Minecraft server world.
minecraft_backup_image_tag: latest
The itzg/mc-backup container image tag to use. See itzg/mc-backup/tags for more available tags.
# All container environment variables can be found at: https://github.com/itzg/docker-mc-backup#common-variables
minecraft_backup_options:
# ...
# Modify the below variables
BACKUP_INTERVAL: 24h
INITIAL_DELAY: 5m
BACKUP_METHOD: restic
RESTIC_REPOSITORY: b2:<bucket>
# ...
The environment variables passed to the itzg/mc-backup container. These environment variables configure backups for the Minecraft server world.
-
Install the required Ansible roles:
ansible-galaxy install -r requirements.yml
-
Create the
mc_hetzner
SSH key pair:ssh-keygen -f ~/.ssh/mc_hetzner -t rsa -b 4096 -N ""
-
Modify the Ansible playbook vars file to configure the Minecraft server Docker container and backup container.
-
Initialise the hcloud Terraform provider:
terraform init
-
Deploy the server:
# Using defaults terraform apply -var="hcloud_token=<API Token>" # Example: Overriding the default server_type terraform apply -var="hcloud_token=<API Token>" -var="server_type=cx31"
-
Enjoy ✨
Later down the line, you may want to modify the Minecraft server container or backup container's environment variables.
To re-run the creation of either without running the entire playbook, use the tags as below:
ansible-playbook -u mc-hetzner -i "<Server IP>", --private-key ~/.ssh/mc_hetzner --tags "minecraft,backup" mc-hetzner.yml
ansible all -u mc-hetzner -i "<Server IP>", --private-key ~/.ssh/mc_hetzner -m ansible.builtin.command -a "docker exec minecraft rcon-cli fwhitelist add <Bedrock player name>"
There are several options for Minecraft Bedrock Edition players on console to connect to the server:
-
Use a CLI application such as jhead/phantom.
-
Use a mobile application such as MC Server Connector or BedrockTogether
- dbrennand - Author
This project is licensed under the MIT License - see the LICENSE for details.