From my previous blog post Build A Fully Functional Minecraft Server In Less Than 10 Minutes With Ansible, I received a large amount of feedback from this Reddit thread, and have been doing a lot of work to refactor the code to improve a number of things:
- Convert to using roles and tasks to split some of the code. The original Ansible Playbook was very easy to read being one file, but it didn’t make the code very reusable. I mainly split the code into pre-install, main, and post-install sections.
- The original code was very straightforward in the goal to install and configure a Vanilla Minecraft server. I added the option to launch one type of modded server as well – a Valhelsia Enhanced Vanilla Mincraft Server (more on that below). The way the code is structured into a common, vanilla, and valhelsia role allows better reuse of the code, and makes it easier to add additional functionality in the future.
- The original code used a lot of “lineinfile” commands to modify the same file over and over. This wasn’t very efficient. One of the suggestions was to use Jinja2 templates to add the variables to the files, and this seemed like a more efficient solution.
- Switched from using screen to tmux. Although using RCON to interact with Minecraft is the best way, I still prefer to have a detachable console that I can log into the server, view, and issue commands; without having the log into the game. I switched from screen, as it is being deprecated in certain Linux distributions, and tmux seems to be more feature rich and better maintained.
Currently I run a Vanilla Minecraft server, as well as a Roguelike Adventures and Dungeons modded server for the players. Some of the players had expressed interest in trying out a Valhelsia Enhanced Vanilla modded server. The mod looks gorgeous from the additional shaders, and the change in gameplay is welcome.
Infrastructure As Code
Rather than spinning up a one-off server, I decided it would be a good opportunity to document the setup process using Infrastructure As Code. I used the Valhelsia Server Installation Guide as a base, and automated all of the steps to set up properly.
This was mainly as a project exercise, but also to make it faster to spin up new servers in the future. Once Minecraft 1.19 comes out, I will be using the Ansible script to rebuild the Vanilla server and reroll the world, so we can explore some of the new features.
Currently the Valhelsia server is running, and is pre-generating chunks to improve performance for when the players start using the server. I’ll be working on some documentation for them, and making sure everything is running properly to ensure a good experience.
This is what I expect I would look like trying to explain how the Ansible roles and tasks map together