I’ve been wanting to have a homelab of things that are “always on”, and a dedicated video game server is one of those dreams. Only trouble is, I don’t really play too many video games. Not gonna let that stop me. Always follow your dreams!
The first node in my home lab is an Optiplex 3050, and it’s a pretty lightweight server. So I’m picking a lightweight game from 1995…
OpenTTD is an open source simulation game based upon Transport Tycoon Deluxe
Installing it is simply a matter of downloading the latest build, unzipping somewhere, and running ./openttd. The reason for downloading instead of using a repository is to keep the client and server versions in sync. If the version of the server is different than the client, there will be problems.
And instead of doing this manually, I wanted to have a repeatable way to install/uninstall the server and client using Ansible. I’m not going to paste it all, just some summary snippets.
INSTALLING THE CLIENT
Here’s the main play, and it installs everything that is common, which is to say, the source code tarball since the server uses the same source code as the client, but is started with a “-D” flag.
- name: Install OpenTTD client
hosts: client
gather_facts: true
roles:
- openttd_common
- name: Install OpenTTD dedicated server
hosts: server
gather_facts: true
roles:
- openttd_common
- openttd_server
Here’s the snippet to extract the tarball…
- name: Extract the OpenTTD release into the install base
ansible.builtin.unarchive:
src: "{{ openttd_tarball_dest }}"
dest: "{{ openttd_install_base }}"
remote_src: true
creates: "{{ openttd_binary }}"
INSTALLING THE SERVER
The server runs everything the client does (common.yml), but also needs a couple more things than the client. Because my server is headless, it had some dependencies that needed to be installed:
openttd_runtime_deps:
- libgomp1
- libfontconfig1
- libfreetype6
- liblzo2-2
A systemd unit file….
- name: Install the OpenTTD systemd unit
ansible.builtin.template:
src: openttd-server.service.j2
dest: /etc/systemd/system/openttd-server.service
mode: "0644"
become: true
notify:
- Reload systemd
- Restart openttd-server
[Service]
Type=simple
User={{ ansible_user_id }}
ExecStart={{ openttd_binary }} -D -c {{ openttd_config_dir }}/openttd.cfg
Restart=on-failure
RestartSec=5
Commands
- ansible-playbook openttd.yml –ask-become-pass
- ansible-playbook openttd.yml –limit client
- ansible-playbook openttd.yml –limit server –ask-become-pass
- ansible-playbook uninstall.yml –ask-become-pass
Rinse and Repeat
Now I have an install and uninstall script for both the clean and/or the server. I can deploy to instances of my homelab in a repeatable manner.
Final Conclusion
After building out this project, I realize how hard it is to write a blog post about it after the fact. Even when using Ansible which is clearly self-documenting. The lesson I learned here is for the next project, I will write my notes here in WordPress in a draft as I go along.