Refactor Minecraft into its own role again for ease of spin-up

This commit is contained in:
Salt 2022-06-14 14:40:21 -05:00
parent f523207316
commit 9796ae1a88
5 changed files with 114 additions and 23 deletions

View File

@ -4,13 +4,17 @@
--- ---
- hosts: vm-minecraft-1.home.mgmt.desu.ltd - hosts: vm-minecraft-1.home.mgmt.desu.ltd
gather_facts: no gather_facts: no
pre_tasks:
- name: include tasks for gameservers
include_tasks: tasks/game/{{ item }}
with_items:
- minecraft-oceanblock.yml
tags: [ always ]
roles: roles:
- role: docker-minecraft
vars:
minecraft_name: oceanblock
minecraft_pack_zip: "https://srv.9iron.club/files/packs/1.16.5-oceanblock/latest.zip"
minecraft_image: "rehashedsalt/minecraft-forge:1.16.5-master"
minecraft_server_properties:
allow-flight: "true"
difficulty: hard
motd: "OCEAN MAN"
tags: [ minecraft ]
- role: backup - role: backup
vars: vars:
backup_s3backup_list_extra: backup_s3backup_list_extra:
@ -21,23 +25,6 @@
- /data/minecraft/botaniapack2-creative - /data/minecraft/botaniapack2-creative
- /data/minecraft/oceanblock/backups - /data/minecraft/oceanblock/backups
tags: [ backup ] tags: [ backup ]
- hosts: vm-minecraft-2.home.mgmt.desu.ltd
gather_facts: no
pre_tasks:
- name: include tasks for gameservers
include_tasks: tasks/game/{{ item }}
with_items:
- minecraft-enigmatica6.yml
tags: [ always ]
roles:
- role: backup
vars:
backup_s3backup_list_extra:
- /data
- /etc
backup_s3backup_exclude_list_extra:
- /data/minecraft/enigmatica6/backups
tags: [ backup ]
- hosts: vm-terraria-1.home.mgmt.desu.ltd - hosts: vm-terraria-1.home.mgmt.desu.ltd
gather_facts: no gather_facts: no
pre_tasks: pre_tasks:

View File

@ -0,0 +1,35 @@
#!/usr/bin/env ansible-playbook
# vim:ft=ansible:
# Overall app settings
minecraft_name: generic
#minecraft_pack_zip: "https://example.com/path/to/pack.zip"
# Container settings
minecraft_uid: 1520
minecraft_gid: 1520
minecraft_state: started
# See the tags for this image for more versions
minecraft_image: rehashedsalt/minecraft-forge:1.16.5-master
minecraft_restart_policy: unless-stopped
minecraft_timezone: "America/Chicago"
# Container network settings
minecraft_external_port: "25565"
minecraft_data_prefix: "/data/minecraft/{{ minecraft_name }}"
# Java settings
minecraft_jvm_args: "-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1"
minecraft_jvm_extra_args: ""
minecraft_xmx: "8G"
minecraft_xms: "4G"
# server.properties
minecraft_server_properties:
allow-flight: true
difficulty: hard
gamemode: survival
level-name: world
level-type: default
max-players: 20
motd: A Minecraft Server
server-port: 25565
spawn-protection: 0
view-distance: 10

View File

@ -0,0 +1,7 @@
#!/usr/bin/env ansible-playbook
# vim:ft=ansible:
- name: restart minecraft {{ minecraft_name }}
docker_container:
name: "minecraft-{{ minecraft_name }}"
state: started
restart: yes

View File

@ -0,0 +1,58 @@
#!/usr/bin/env ansible-playbook
# vim:ft=ansible:
---
- name: assure minecraft {{ minecraft_name }} directory structure
file:
state: directory
owner: "{{ minecraft_uid }}"
group: "{{ minecraft_gid }}"
mode: "0750"
path: "{{ item }}"
# We recurse here since these directories *and all of their contents*
# should be read-write by the container without exception.
recurse: yes
with_items:
- "{{ minecraft_data_prefix }}/backups"
- "{{ minecraft_data_prefix }}/logs"
- "{{ minecraft_data_prefix }}/world"
- name: assure minecraft {{ minecraft_name }} files
file:
state: touch
owner: "{{ minecraft_uid }}"
group: "{{ minecraft_gid }}"
mode: "0640"
path: "{{ item }}"
with_items:
- "{{ minecraft_data_prefix }}/ops.json"
- "{{ minecraft_data_prefix }}/server.properties"
- name: assure {{ minecraft_name }} server properties
lineinfile:
state: present
regexp: "^{{ item.key }}"
line: "{{ item.key }}={{ item.value }}"
path: "{{ minecraft_data_prefix }}/server.properties"
with_dict: "{{ minecraft_server_properties }}"
notify: "restart minecraft {{ minecraft_name }}"
- name: assure minecraft {{ minecraft_name }} container
docker_container:
name: "minecraft-{{ minecraft_name }}"
state: started
image: "{{ minecraft_image }}"
restart_policy: "{{ minecraft_restart_policy }}"
pull: yes
user: "{{ minecraft_uid }}:{{ minecraft_gid }}"
env:
TZ: "{{ minecraft_timezone }}"
ARGS: "{{ minecraft_jvm_args }} {{ minecraft_jvm_extra_args }}"
JRE_XMX: "{{ minecraft_xmx }}"
JRE_XMS: "{{ minecraft_xms }}"
FORGE_PACK_ZIP: "{{ minecraft_pack_zip }}"
ports:
- "{{ minecraft_external_port }}:25565/tcp"
- "{{ minecraft_external_port }}:25565/udp"
volumes:
- "{{ minecraft_data_prefix }}/backups:/minecraft/backups"
- "{{ minecraft_data_prefix }}/logs:/minecraft/logs"
- "{{ minecraft_data_prefix }}/ops.json:/minecraft/ops.json"
- "{{ minecraft_data_prefix }}/server.properties:/minecraft/server.properties"
- "{{ minecraft_data_prefix }}/world:/minecraft/world"

View File

@ -0,0 +1,4 @@
{{ ansible_managed }}
{% for property in minecraft_server_properties %}
{{ property.key }}={{ property.value }}
{% endfor %}