Skip to content

dbrennand/mc-hetzner

Repository files navigation

mc-hetzner

Ansible-Lint

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.

Prerequisites

Playbook variables

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.

Usage

  1. Install the required Ansible roles:

    ansible-galaxy install -r requirements.yml
  2. Create the mc_hetzner SSH key pair:

    ssh-keygen -f ~/.ssh/mc_hetzner -t rsa -b 4096 -N ""
  3. Modify the Ansible playbook vars file to configure the Minecraft server Docker container and backup container.

  4. Initialise the hcloud Terraform provider:

    terraform init
  5. 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"
  6. Enjoy ✨

FAQs

How do I reconfigure the Minecraft or Backup container?

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

How do I whitelist a Minecraft Bedrock Edition player using Floodgate?

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>"

How do Minecraft Bedrock Edition players on console connect to the server?

There are several options for Minecraft Bedrock Edition players on console to connect to the server:

  1. Use a CLI application such as jhead/phantom.

  2. Use a mobile application such as MC Server Connector or BedrockTogether

Authors & Contributors

License

This project is licensed under the MIT License - see the LICENSE for details.