Add Minecraft server role

This commit is contained in:
Salt 2020-02-23 23:45:11 -06:00
parent 884ed33ab6
commit eb5c6a62b0
6 changed files with 186 additions and 1 deletions

11
ec2.yml
View File

@ -5,10 +5,19 @@
roles: roles:
- common - common
- user - user
- hosts: tag_minecraft_botaniapack
vars:
mcname: "botaniapack-1"
mczip: "https://www.assburgers.club/files/botaniapack-1.zip"
mcforge: "1.10.2-12.18.3.2511"
mcport: "25565"
mcmotd: "First time on Assburgers edition"
roles:
- minecraft
- hosts: tag_ansiblehost_true - hosts: tag_ansiblehost_true
roles: roles:
- ansiblehost - ansiblehost
- hosts: tag_role_nextcloud - hosts: tag_www_true
vars: vars:
mysql_root_password: !vault | mysql_root_password: !vault |
$ANSIBLE_VAULT;1.1;AES256 $ANSIBLE_VAULT;1.1;AES256

View File

@ -0,0 +1,2 @@
# Yes, we accept the EULA
eula=true

View File

@ -0,0 +1,37 @@
#
# Licensed under the terms of the MIT license
# Source: https://github.com/agowa338/MinecraftSystemdUnit/
# vim:ft=dosini:
#
[Unit]
Description=Minecraft Server %i
After=network.target
[Service]
User=minecraft
Group=mc-admin
WorkingDirectory=/var/minecraft/%i
# Hide other users from unit
PrivateUsers=true
# Read only mapping of /usr /boot and /etc
ProtectSystem=full
ProtectHome=true
# Implies MountFlags=slave
ProtectKernelTunables=true
# Implies NoNewPrivileges=yes
ProtectKernelModules=true
# Implies MountAPIVFS=yes
ProtectControlGroups=true
ExecStart=/bin/sh -c '/usr/bin/screen -DmS mc-%i /usr/bin/java -Xms512M -Xmx2048M -jar server.jar nogui'
ExecReload=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "reload"\\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say Server is going down: Service was stopped"\\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"\\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"\\015'
ExecStop=/bin/sleep 10
Restart=on-failure
RestartSec=60s

View File

@ -0,0 +1,2 @@
---
allow_duplicates: yes

View File

@ -0,0 +1,95 @@
#!/usr/bin/ansible-playbook
# vim:ft=ansible:
---
- name: Set up Minecraft user
block:
- name: Install required packages
apt:
name: "{{ packages }}"
vars:
packages:
- openjdk-8-jre
- screen
- unzip
- name: Assure minecraft admin group
group:
name: mc-admin
- name: Assure server user
user:
name: minecraft
group: mc-admin
system: yes
home: /var/minecraft
- name: Assure var directory
file:
path: /var/minecraft
state: directory
owner: root
group: mc-admin
# Sticky, SetGID
mode: "3770"
- name: Assure systemd unit
copy:
src: "minecraft@.service"
dest: "/etc/systemd/system/minecraft@.service"
- name: Reload available daemons
systemd:
daemon_reload: yes
become: yes
- name: Set up Minecraft server
block:
- name: Create server directory
file:
path: "/var/minecraft/{{ mcname }}"
state: directory
- name: Check for existing install
stat:
path: "/var/minecraft/{{ mcname }}/forge-{{ mcforge }}-universal.jar"
register: stat_mcroot_forgejar
- name: Unpack archive
block:
- name: Download zip
get_url:
dest: "/var/minecraft/{{ mcname }}/modpack.zip"
url: "{{ mczip }}"
- name: Unpack zip
unarchive:
src: "/var/minecraft/{{ mcname }}/modpack.zip"
remote_src: yes
dest: "/var/minecraft/{{ mcname }}"
- name: Remove zip
file:
path: "/var/minecraft/{{ mcname }}/modpack.zip"
state: absent
- name: Template out server.properties
template:
src: server.properties
dest: "/var/minecraft/{{ mcname }}/server.properties"
- name: Accept EULA
copy:
src: "eula.txt"
dest: "/var/minecraft/{{ mcname }}/eula.txt"
- name: Download Forge
get_url:
dest: "/var/minecraft/{{ mcname }}/installer.jar"
# Accurate as of 2020-02-23
url: "https://files.minecraftforge.net/maven/net/minecraftforge/forge/{{ mcforge }}/forge-{{ mcforge }}-installer.jar"
- name: Install Forge
# Note: This also installs a Minecraft server, thankfully
command:
chdir: "/var/minecraft/{{ mcname }}"
argv:
- /usr/bin/java
- "-jar"
- "/var/minecraft/{{ mcname }}/installer.jar"
- "--installServer"
args:
creates: "/var/minecraft/{{ mcname }}/forge-{{ mcforge }}-universal.jar"
- name: Link server jar
file:
path: "/var/minecraft/{{ mcname }}/server.jar"
src: "/var/minecraft/{{ mcname }}/forge-{{ mcforge }}-universal.jar"
state: link
when: not stat_mcroot_forgejar.stat.exists
become: yes
become_user: minecraft

View File

@ -0,0 +1,40 @@
#Minecraft server properties
#Fri Aug 23 01:44:29 UTC 2019
spawn-protection=0
max-tick-time=60000
generator-settings=
force-gamemode=false
allow-nether=true
gamemode=0
broadcast-console-to-ops=true
enable-query=false
player-idle-timeout=0
difficulty=3
spawn-monsters=true
op-permission-level=4
pvp=true
snooper-enabled=false
level-type=default
hardcore=false
enable-command-block=true
max-players=8
network-compression-threshold=256
resource-pack-sha1=
max-world-size=29999984
server-port={{ mcport }}
server-ip=
spawn-npcs=true
allow-flight=true
level-name=world
view-distance=12
resource-pack=
spawn-animals=true
white-list=false
generate-structures=true
online-mode=true
max-build-height=256
level-seed=
prevent-proxy-connections=false
use-native-transport=true
enable-rcon=false
motd={{ mcmotd }}