Skip to content

borisskert/ansible_minecraftserver

Repository files navigation

ansible_minecraftserver

This is an ansible role to install a minecraft server as docker container controlled by systemd.

I'm using itzg's docker image. Thanks for your great work!

System requirements

  • Docker
  • docker-compose
  • Systemd

Role requirements

  • (none, so far)

Tasks

  • Template docker-compose file environment
  • Create data volume directory for docker container
  • Setup systemd unit file
  • Start/Restart systemd service

Role parameters

Variable Type Mandatory? Default Description
minecraftserver_state text no 'present' If absent removes the docker configuration and systemd service
minecraftserver_image_version text no 'latest' itzg's Docker image version
minecraftserver_version text no '' Minecraft Server version (e.g. 1.16.5, default: latest version will be downloaded)
minecraftserver_interface text no 0.0.0.0 Mapped network interface
minecraftserver_port text no 25565 Mapped network port
minecraftserver_data_volume_directory text no /srv/minecraftserver/minecraft-data Location of your data volume directory
minecraftserver_environment key-value map no {} Specifies the environment for the docker image (See itzg's documentation)
minecraftserver_force_remove boolean no false Only for state absent: Specifies if your data volume directory will be deleted on when uninstalling

Example Playbook

Add to requirements.yml:

- name: install-minecraftserver
  src: https://github.com/borisskert/ansible_minecraftserver.git
  scm: git

Example playbook.yml:

- hosts: servers
  roles:
    - role: install-minecraftserver
      minecraftserver_state: present
      minecraftserver_image_version: latest
      minecraftserver_version: '1.16.5'
      minecraftserver_interface: 0.0.0.0
      minecraftserver_port: 25565
      minecraftserver_data_volume_directory: /srv/minecraftserver/minecraft-data
      minecraftserver_environment:
        SEED: 1785852800490497919
        VIEW_DISTANCE: 10
        MODE: creative
        MOTD: My super cool MC server

Example playbook.yml for uninstall:

- hosts: servers
  roles:
    - role: install-minecraftserver
      minecraftserver_state: absent
      minecraftserver_force_remove: true

Testing

Requirements:

Run within docker

molecule test && molecule test --scenario-name all-parameters && molecule test --scenario-name state-absent && molecule test --scenario-name with-environment && molecule test --scenario-name state-absent-force-remove-persistent-data

Run within Vagrant

molecule test -s vagrant-default && molecule test -s vagrant-all-parameters && molecule test --scenario-name vagrant-state-absent && molecule test --scenario-name vagrant-with-environment && molecule test --scenario-name vagrant-state-absent-force-remove-persistent-data

I recommend to use pyenv for local testing. Within the Github Actions pipeline I use my own molecule Docker image.

License

MIT

Author Information

Further links