Post

Deploying an UT2004 Server with Ansible

Late last year, Epic made a surprisingly good decision and gave the community its blessing to bring Unreal Tournament 2004 back to life. Earlier this year, OldUnreal released the first public version of its work, including full-game installers and a modernized patch.

The installers download the original UT2004 ECE image, install the game, and automatically apply the latest OldUnreal patch. The project also brings bug fixes, quality-of-life improvements, and much better compatibility with modern Windows, Linux, and macOS systems. After years of Unreal Tournament being essentially abandoned, seeing the community officially allowed to maintain one of its best games is pretty amazing.

For those who never played it, UT2004 was one of the great arena shooters and, to me, probably the best multiplayer FPS ever made, tied very closely with Quake III Arena. It had basically everything I want from a fast-paced FPS. Great weapons, ranging from hitscan to projectile and more tactical options; extremely fast and acrobatic movement with double jumps, wall jumps, and all sorts of combinations; and, most importantly, excellent map control.

Whether in a duel or Team Deathmatch, which was what I played much more extensively, being good at shooting was not enough. You had to move well and understand the arena. That meant watching the clock, timing weapon and power-up spawns, controlling routes, reading opponent movement, and anticipating where players would be rather than simply reacting when they appeared on screen.

And if that wasn’t enough, the game was incredibly customizable. For competitive play, UTComp made it even better. The mutator added features such as warmup mode, brightskins, hitsounds, and several other competitive-oriented improvements that became almost inseparable from the way many of us played the game.

I don’t expect any of this to suddenly bring UT2004 back into the mainstream. It comes from a rather different era of multiplayer shooters. It is fast, cruel, unforgiving, mechanically demanding, and requires constant focus. Which is also exactly why it was so much fun.

Installing the game today is surprisingly straightforward through the OldUnreal download page.

Setting up a proper dedicated server is slightly less straightforward. It isn’t particularly difficult, but there are enough dependencies, configuration files, ports, services, maps, and mutators involved that doing it manually gets tedious.

Since I went through the trouble of setting one up myself, I naturally did the sensible thing and automated the whole process with Ansible.

The playbook below:

  • installs UT2004 using the OldUnreal Linux installer
  • creates a dedicated service account and filesystem structure
  • configures an independent server instance
  • installs UTComp v1.7a
  • installs DM-Campgrounds2004-LE
  • enables UTComp’s enhanced netcode
  • configures the server as a systemd service
  • configures UFW for the required ports
  • optionally enables UT2004’s WebAdmin interface

It assumes a Debian/Ubuntu-style host and uses modules from the community.general collection, so make sure you have it installed on your Ansible controller:

1
ansible-galaxy collection install community.general

If WebAdmin is enabled, change ut_admin_password before running the playbook. The example also restricts WebAdmin to 192.168.0.0/16; adjust ut_webadmin_allowed_from to your LAN or VPN subnet. I would strongly avoid exposing WebAdmin directly to the public Internet.

And with that, here’s the playbook:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
---
- name: Install UT2004 (OldUnreal) + configure Local Deathmatch #1 as systemd instance
  hosts: ut2004
  become: true

  vars:
    ut_user: ut2004
    ut_group: ut2004

    ut_install_dir: /opt/ut2004
    ut_state_root: /var/lib/ut2004
    ut_log_dir: /var/log/ut2004
    ut_cfg_root: /etc/ut2004

    # OldUnreal installer script (raw GitHub)
    ut_installer_url: "https://raw.githubusercontent.com/OldUnreal/FullGameInstallers/master/Linux/install-ut2004.sh"

    # Instance
    ut_instance: "dm1"
    ut_server_name: "Local Deathmatch #1"
    ut_short_name: "DM #1"
    ut_map: "DM-Rankin"
    ut_game_type: "XGame.xDeathMatch"
    ut_game_port: 7777
    ut_max_players: 8

    # WebAdmin
    ut_enable_webadmin: true
    ut_webserver_port: 8080
    ut_webadmin_allowed_from: "192.168.0.0/16"
    ut_admin_password: "CHANGE_ME"

    # Derived ports
    ut_query_port: "{{ ut_game_port | int + 1 }}"
    ut_gamespy_port: "{{ ut_game_port | int + 10 }}"
    ut_gamespy_extra_port: "{{ ut_gamespy_port | int + 1 }}"
    ut_beacon_port: "{{ ut_game_port | int - 1 }}"

    # Executable
    ut_ucc: "{{ ut_install_dir }}/System/UCC"

    # Instance paths
    ut_instance_dir: "{{ ut_cfg_root }}/{{ ut_instance }}"
    ut_instance_state: "{{ ut_state_root }}/{{ ut_instance }}"
    ut_instance_env: "{{ ut_cfg_root }}/{{ ut_instance }}.env"

    # Per-instance ini stored in System/
    ut_ini: "{{ ut_instance }}.ini"
    ut_system_ini: "{{ ut_install_dir }}/System/{{ ut_ini }}"
    ut_default_ini: "{{ ut_install_dir }}/System/Default.ini"

    # UTComp v17a
    ut_enable_utcomp: true
    utcomp_url: "https://unreal-archive-files-eu.s3.de.io.cloud.ovh.net/Unreal%20Tournament%202004/Mutators/U/c/0/d1d3ba/utcompv17a_116.7z"
    utcomp_archive_dest: "/tmp/utcompv17a_116.7z"
    utcomp_mutator: "utcompv17a.MutUTComp"
    utcomp_serverpackage: "utcompv17a"
    utcomp_creates: "{{ ut_install_dir }}/System/utcompv17a.u"

    # Campgrounds LE
    ut_enable_maps: true
    ut_campgrounds_url: "https://unreal-archive-files-eu.s3.de.io.cloud.ovh.net/Unreal%20Tournament%202004/Maps/DeathMatch/C/7/e/047320/DM-CampGrounds2004-LE.zip"
    ut_campgrounds_zip: "/tmp/DM-CampGrounds2004-LE.zip"
    ut_campgrounds_creates: "{{ ut_install_dir }}/Maps/DM-Campgrounds2004-LE.ut2"

  pre_tasks:
    - name: Install dependencies + ufw
      ansible.builtin.apt:
        update_cache: true
        state: present
        name:
          - bash
          - coreutils
          - jq
          - tar
          - curl
          - p7zip-full
          - unshield
          - ca-certificates
          - ufw
          - lbzip2
          - unzip

    - name: Require a non-default WebAdmin password
      when: ut_enable_webadmin
      ansible.builtin.assert:
        that:
          - ut_admin_password != "CHANGE_ME"
          - ut_admin_password | length >= 12
        fail_msg: "Set a secure ut_admin_password before enabling WebAdmin."

  tasks:
    - name: Ensure group exists
      ansible.builtin.group:
        name: "{{ ut_group }}"
        system: true

    - name: Ensure user exists
      ansible.builtin.user:
        name: "{{ ut_user }}"
        group: "{{ ut_group }}"
        system: true
        create_home: false
        shell: /usr/sbin/nologin

    - name: Create base directories
      ansible.builtin.file:
        path: "{{ item }}"
        state: directory
        owner: "{{ ut_user }}"
        group: "{{ ut_group }}"
        mode: "0755"
      loop:
        - "{{ ut_install_dir }}"
        - "{{ ut_state_root }}"
        - "{{ ut_log_dir }}"
        - "{{ ut_cfg_root }}"
        - "{{ ut_instance_dir }}"
        - "{{ ut_instance_state }}"

    - name: Download OldUnreal UT2004 installer script
      ansible.builtin.get_url:
        url: "{{ ut_installer_url }}"
        dest: /usr/local/bin/install-ut2004.sh
        mode: "0755"

    - name: Run OldUnreal installer headlessly (idempotent) with logfile and ToS accept
      ansible.builtin.shell: |
        set -euo pipefail
        mkdir -p "{{ ut_log_dir }}"
        printf "y\n" | /usr/local/bin/install-ut2004.sh \
          --ui-mode none \
          --application-entry skip \
          --desktop-shortcut skip \
          --no-unrealed \
          --destination "{{ ut_install_dir }}" \
          > "{{ ut_log_dir }}/installer.log" 2>&1
      args:
        creates: "{{ ut_ucc }}"
        executable: /bin/bash
      environment:
        HOME: "{{ ut_state_root }}"
        XDG_DATA_HOME: "{{ ut_state_root }}"

    - name: Ensure install dir ownership
      ansible.builtin.file:
        path: "{{ ut_install_dir }}"
        owner: "{{ ut_user }}"
        group: "{{ ut_group }}"
        recurse: true

    - name: Ensure UCC is executable
      ansible.builtin.file:
        path: "{{ ut_ucc }}"
        mode: "0755"

    # ---- UTComp install ----
    - name: Download UTComp v17a archive
      when: ut_enable_utcomp
      ansible.builtin.get_url:
        url: "{{ utcomp_url }}"
        dest: "{{ utcomp_archive_dest }}"
        mode: "0644"

    - name: Extract UTComp v17a into UT install dir
      when: ut_enable_utcomp
      ansible.builtin.command: >
        7z x -y "{{ utcomp_archive_dest }}" -o"{{ ut_install_dir }}"
      args:
        creates: "{{ utcomp_creates }}"
      notify: restart ut2004 instance

    # ---- Maps install ----
    - name: Download DM-Campgrounds2004-LE
      when: ut_enable_maps
      ansible.builtin.get_url:
        url: "{{ ut_campgrounds_url }}"
        dest: "{{ ut_campgrounds_zip }}"
        mode: "0644"

    - name: Extract DM-Campgrounds2004-LE into UT install dir
      when: ut_enable_maps
      ansible.builtin.unarchive:
        src: "{{ ut_campgrounds_zip }}"
        dest: "{{ ut_install_dir }}"
        remote_src: true
        creates: "{{ ut_campgrounds_creates }}"
      notify: restart ut2004 instance

    - name: Remove stray Campgrounds map accidentally included under System
      when: ut_enable_maps
      ansible.builtin.file:
        path: "{{ ut_install_dir }}/System/DM-Campgrounds2004-LE.ut2"
        state: absent

    - name: Ensure install dir ownership after mods and maps
      ansible.builtin.file:
        path: "{{ ut_install_dir }}"
        owner: "{{ ut_user }}"
        group: "{{ ut_group }}"
        recurse: true

    # ---- Per-instance environment file ----
    - name: Write per-instance environment file
      ansible.builtin.copy:
        dest: "{{ ut_instance_env }}"
        owner: root
        group: root
        mode: "0644"
        content: |
          UT_MAP={{ ut_map }}
          UT_GAME_TYPE={{ ut_game_type }}
          UT_GAME_PORT={{ ut_game_port }}
          UT_INI={{ ut_ini }}
          UT_LOG=server-{{ ut_instance }}.log
          UT_STATE={{ ut_instance_state }}
          UT_MUTATORS={{ utcomp_mutator if ut_enable_utcomp else "" }}
      notify: restart ut2004 instance

    # ---- Per-instance configuration ----
    - name: Initialize per-instance ini from Default.ini
      ansible.builtin.copy:
        remote_src: true
        src: "{{ ut_default_ini }}"
        dest: "{{ ut_system_ini }}"
        owner: "{{ ut_user }}"
        group: "{{ ut_group }}"
        mode: "0640"
        force: false
      notify: restart ut2004 instance

    - name: Set ServerName
      community.general.ini_file:
        path: "{{ ut_system_ini }}"
        section: "Engine.GameReplicationInfo"
        option: "ServerName"
        value: "{{ ut_server_name }}"
      notify: restart ut2004 instance

    - name: Set ShortName
      community.general.ini_file:
        path: "{{ ut_system_ini }}"
        section: "Engine.GameReplicationInfo"
        option: "ShortName"
        value: "{{ ut_short_name }}"
      notify: restart ut2004 instance

    - name: Set MaxPlayers
      community.general.ini_file:
        path: "{{ ut_system_ini }}"
        section: "Engine.GameInfo"
        option: "MaxPlayers"
        value: "{{ ut_max_players }}"
      notify: restart ut2004 instance

    # ---- LAN beacon ----
    - name: Enable LAN beacon
      community.general.ini_file:
        path: "{{ ut_system_ini }}"
        section: "IpDrv.UdpBeacon"
        option: "DoBeacon"
        value: "True"
      notify: restart ut2004 instance

    - name: Set LAN beacon port
      community.general.ini_file:
        path: "{{ ut_system_ini }}"
        section: "IpDrv.UdpBeacon"
        option: "BeaconPort"
        value: "{{ ut_beacon_port }}"
      notify: restart ut2004 instance

    # ---- UTComp ----
    - name: Ensure UTComp ServerPackages entry is present
      when: ut_enable_utcomp
      community.general.ini_file:
        path: "{{ ut_system_ini }}"
        section: "Engine.GameEngine"
        option: "ServerPackages"
        value: "{{ utcomp_serverpackage }}"
        exclusive: false
      notify: restart ut2004 instance

    - name: Enable UTComp Enhanced Netcode
      when: ut_enable_utcomp
      community.general.ini_file:
        path: "{{ ut_system_ini }}"
        section: "utcompv17a.MutUTComp"
        option: "bEnableEnhancedNetCode"
        value: "True"
      notify: restart ut2004 instance

    # ---- WebAdmin ----
    - name: Enable WebAdmin
      when: ut_enable_webadmin
      community.general.ini_file:
        path: "{{ ut_system_ini }}"
        section: "UWeb.WebServer"
        option: "bEnabled"
        value: "True"
      notify: restart ut2004 instance

    - name: Set WebAdmin listen port
      when: ut_enable_webadmin
      community.general.ini_file:
        path: "{{ ut_system_ini }}"
        section: "UWeb.WebServer"
        option: "ListenPort"
        value: "{{ ut_webserver_port }}"
      notify: restart ut2004 instance

    - name: Set WebAdmin password
      when: ut_enable_webadmin
      community.general.ini_file:
        path: "{{ ut_system_ini }}"
        section: "Engine.AccessControl"
        option: "AdminPassword"
        value: "{{ ut_admin_password }}"
      no_log: true
      notify: restart ut2004 instance

    # ---- systemd runner wrapper ----
    - name: Install UT2004 instance runner wrapper
      ansible.builtin.copy:
        dest: /usr/local/bin/ut2004-run-instance.sh
        mode: "0755"
        owner: root
        group: root
        content: |
          #!/usr/bin/env bash
          set -euo pipefail

          : "${UT_MAP:?missing UT_MAP}"
          : "${UT_GAME_TYPE:?missing UT_GAME_TYPE}"
          : "${UT_GAME_PORT:?missing UT_GAME_PORT}"
          : "${UT_INI:?missing UT_INI}"
          : "${UT_LOG:?missing UT_LOG}"

          MUTATOR_FRAGMENT=""
          if [[ -n "${UT_MUTATORS:-}" ]]; then
            MUTATOR_FRAGMENT="?Mutator=${UT_MUTATORS}"
          fi

          exec "{{ ut_ucc }}" server \
            "${UT_MAP}?game=${UT_GAME_TYPE}?Port=${UT_GAME_PORT}${MUTATOR_FRAGMENT}" \
            ini="${UT_INI}" log="${UT_LOG}" -nohomedir
      notify: restart ut2004 instance

    # ---- systemd template unit ----
    - name: Install systemd template unit ut2004@.service
      ansible.builtin.copy:
        dest: /etc/systemd/system/ut2004@.service
        mode: "0644"
        content: |
          [Unit]
          Description=Unreal Tournament 2004 Dedicated Server (%i)
          After=network-online.target
          Wants=network-online.target

          [Service]
          Type=simple
          User={{ ut_user }}
          Group={{ ut_group }}
          WorkingDirectory={{ ut_install_dir }}/System
          EnvironmentFile={{ ut_cfg_root }}/%i.env

          Environment=HOME={{ ut_state_root }}/%i
          Environment=XDG_DATA_HOME={{ ut_state_root }}/%i

          ExecStart=/usr/local/bin/ut2004-run-instance.sh
          Restart=on-failure
          RestartSec=5
          StandardOutput=append:{{ ut_log_dir }}/ut2004-%i.out.log
          StandardError=append:{{ ut_log_dir }}/ut2004-%i.err.log
          LimitNOFILE=65535

          [Install]
          WantedBy=multi-user.target
      notify: restart ut2004 instance

    - name: Enable and start the UT2004 instance
      ansible.builtin.systemd:
        name: "ut2004@{{ ut_instance }}"
        enabled: true
        state: started
        daemon_reload: true

    # ---- Firewall (UFW) ----
    - name: Allow OpenSSH in UFW
      community.general.ufw:
        rule: allow
        name: OpenSSH

    - name: Allow UT2004 beacon port
      community.general.ufw:
        rule: allow
        port: "{{ ut_beacon_port }}"
        proto: udp

    - name: Allow UT2004 game port
      community.general.ufw:
        rule: allow
        port: "{{ ut_game_port }}"
        proto: udp

    - name: Allow UT2004 query port
      community.general.ufw:
        rule: allow
        port: "{{ ut_query_port }}"
        proto: udp

    - name: Allow UT2004 GameSpy query port
      community.general.ufw:
        rule: allow
        port: "{{ ut_gamespy_port }}"
        proto: udp

    - name: Allow UT2004 GameSpy extra port
      community.general.ufw:
        rule: allow
        port: "{{ ut_gamespy_extra_port }}"
        proto: udp

    - name: Allow WebAdmin from trusted network
      when: ut_enable_webadmin
      community.general.ufw:
        rule: allow
        port: "{{ ut_webserver_port }}"
        proto: tcp
        src: "{{ ut_webadmin_allowed_from }}"

    - name: Ensure UFW is enabled
      community.general.ufw:
        state: enabled
        policy: deny

  handlers:
    - name: restart ut2004 instance
      ansible.builtin.systemd:
        name: "ut2004@{{ ut_instance }}"
        state: restarted
        daemon_reload: true

Once your inventory contains the target under the ut2004 group, deployment is just:

1
ansible-playbook -i inventory.ini ut2004.yml

And that’s it. One playbook later, you have a persistent UT2004 Deathmatch server, UTComp, Campgrounds, WebAdmin, firewall rules, and systemd taking care of the process.

You don’t need any of this just to play the game, of course. You can create matches locally without touching Ansible, Linux servers, or any of this unnecessary infrastructure.

But if you’re going to bring UT2004 back, you might as well do it properly.

Happy fragging!