2020-02-23 23:45:11 -06:00
|
|
|
#!/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
|
2020-06-01 21:28:09 -05:00
|
|
|
template:
|
2020-02-23 23:45:11 -06:00
|
|
|
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
|
2020-06-24 09:20:25 -05:00
|
|
|
- name: Download zip
|
|
|
|
get_url:
|
|
|
|
dest: "/var/minecraft/{{ mcname }}/modpack.zip"
|
|
|
|
url: "{{ mczip }}"
|
|
|
|
register: get_mcpack
|
2020-06-25 08:42:29 -05:00
|
|
|
- name: Template out scripts
|
|
|
|
template:
|
|
|
|
src: "{{ item.src }}"
|
|
|
|
dest: "/var/minecraft/{{ mcname }}/{{ item.dest }}"
|
|
|
|
mode: "{{ item.mode }}"
|
|
|
|
loop:
|
|
|
|
- { src: "install.sh", dest: "install.sh", mode: "0755" }
|
|
|
|
- { src: "recover.sh", dest: "recover.sh", mode: "0755" }
|
2020-06-24 09:33:43 -05:00
|
|
|
- name: Install modpack
|
2020-02-23 23:45:11 -06:00
|
|
|
block:
|
2020-06-24 10:19:23 -05:00
|
|
|
- name: Disable service
|
|
|
|
systemd:
|
|
|
|
name: "minecraft@{{ mcname }}"
|
|
|
|
state: stopped
|
2020-06-24 10:21:09 -05:00
|
|
|
become: yes
|
|
|
|
become_user: root
|
2020-06-24 10:18:09 -05:00
|
|
|
- name: Remove remnants of old pack
|
|
|
|
file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
state: absent
|
|
|
|
loop:
|
|
|
|
- "/var/minecraft/{{ mcname }}/config"
|
|
|
|
- "/var/minecraft/{{ mcname }}/coremods"
|
2020-07-25 22:15:09 -05:00
|
|
|
- "/var/minecraft/{{ mcname }}/local"
|
2020-06-24 10:18:09 -05:00
|
|
|
- "/var/minecraft/{{ mcname }}/mods"
|
|
|
|
- "/var/minecraft/{{ mcname }}/scripts"
|
2020-06-24 10:51:48 -05:00
|
|
|
- "/var/minecraft/{{ mcname }}/server.jar"
|
2020-02-23 23:45:11 -06:00
|
|
|
- name: Unpack zip
|
|
|
|
unarchive:
|
|
|
|
src: "/var/minecraft/{{ mcname }}/modpack.zip"
|
|
|
|
remote_src: yes
|
|
|
|
dest: "/var/minecraft/{{ mcname }}"
|
2020-06-24 09:33:43 -05:00
|
|
|
notify: "restart minecraft {{ mcname }}"
|
2020-06-24 10:38:24 -05:00
|
|
|
- name: Run install script
|
2020-06-24 09:20:25 -05:00
|
|
|
command:
|
|
|
|
chdir: "/var/minecraft/{{ mcname }}"
|
|
|
|
argv:
|
2020-06-24 10:38:24 -05:00
|
|
|
- bash
|
|
|
|
- "./install.sh"
|
2020-06-24 09:33:43 -05:00
|
|
|
notify: "restart minecraft {{ mcname }}"
|
|
|
|
when: get_mcpack is changed
|
|
|
|
- name: Check for Forge
|
|
|
|
stat:
|
2020-06-24 10:51:48 -05:00
|
|
|
path: "/var/minecraft/{{ mcname }}/server.jar"
|
2020-06-24 09:33:43 -05:00
|
|
|
register: stat_mcroot_forgejar
|
|
|
|
- name: Install Forge
|
|
|
|
block:
|
2020-02-23 23:45:11 -06:00
|
|
|
- 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"
|
2020-06-24 09:33:43 -05:00
|
|
|
register: get_forge
|
2020-02-23 23:45:11 -06:00
|
|
|
- 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"
|
2020-06-24 10:51:11 -05:00
|
|
|
- name: Find classic jar name
|
|
|
|
stat:
|
|
|
|
path: "/var/minecraft/{{ mcname }}/forge-{{ mcforge }}-universal.jar"
|
|
|
|
register: stat_mcroot_newjar
|
|
|
|
- name: Link old-style server jar
|
2020-02-23 23:45:11 -06:00
|
|
|
file:
|
|
|
|
path: "/var/minecraft/{{ mcname }}/server.jar"
|
|
|
|
src: "/var/minecraft/{{ mcname }}/forge-{{ mcforge }}-universal.jar"
|
|
|
|
state: link
|
2020-06-24 10:51:11 -05:00
|
|
|
when: stat_mcroot_newjar.stat.exists
|
|
|
|
- name: Link new-style server jar
|
|
|
|
file:
|
|
|
|
path: "/var/minecraft/{{ mcname }}/server.jar"
|
|
|
|
src: "/var/minecraft/{{ mcname }}/forge-{{ mcforge }}.jar"
|
|
|
|
state: link
|
|
|
|
when: not stat_mcroot_newjar.stat.exists
|
2020-06-24 09:33:43 -05:00
|
|
|
when: not stat_mcroot_forgejar.stat.exists
|
2020-06-25 08:42:29 -05:00
|
|
|
- name: Check for world
|
|
|
|
stat:
|
|
|
|
path: "/var/minecraft/{{ mcname }}/world"
|
|
|
|
register: stat_mcroot_world
|
|
|
|
- name: Recover world, if available
|
|
|
|
block:
|
2020-06-25 08:57:58 -05:00
|
|
|
- name: Stop server
|
|
|
|
systemd:
|
|
|
|
name: "minecraft@{{ mcname }}"
|
|
|
|
state: stopped
|
2020-06-25 08:42:29 -05:00
|
|
|
- name: Run recover script
|
|
|
|
command:
|
|
|
|
chdir: "/var/minecraft/{{ mcname }}"
|
|
|
|
argv:
|
|
|
|
- bash
|
|
|
|
- "./recover.sh"
|
|
|
|
notify: "restart minecraft {{ mcname }}"
|
2020-06-26 20:27:46 -05:00
|
|
|
become: yes
|
|
|
|
become_user: root
|
|
|
|
- name: Change permissions of world
|
|
|
|
file:
|
|
|
|
path: "/var/minecraft/{{ mcname }}/world"
|
|
|
|
state: directory
|
|
|
|
owner: minecraft
|
|
|
|
group: mc-admin
|
2020-06-25 08:50:01 -05:00
|
|
|
when: not stat_mcroot_world.stat.exists
|
2020-02-26 18:53:20 -06:00
|
|
|
- name: Configure server
|
|
|
|
block:
|
|
|
|
- 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"
|
2020-02-23 23:45:11 -06:00
|
|
|
become: yes
|
|
|
|
become_user: minecraft
|
2020-06-08 20:10:58 -05:00
|
|
|
- name: Set up system
|
|
|
|
block:
|
|
|
|
- name: Enable service
|
|
|
|
systemd:
|
|
|
|
name: "minecraft@{{ mcname }}"
|
|
|
|
enabled: yes
|
|
|
|
state: started
|
|
|
|
- name: Template out backup module
|
|
|
|
template:
|
|
|
|
src: "backup.sh"
|
|
|
|
dest: "/opt/backups/modules/minecraft-{{ mcname }}.sh"
|
|
|
|
mode: "0600"
|
2020-06-30 05:52:18 -05:00
|
|
|
- name: Assure CNAME record
|
|
|
|
route53:
|
|
|
|
state: present
|
2020-07-23 21:02:56 -05:00
|
|
|
overwrite: yes
|
2020-06-30 05:52:18 -05:00
|
|
|
zone: "{{ zone }}"
|
|
|
|
type: CNAME
|
|
|
|
record: "{{ mcname }}.mc.{{ zone }}."
|
|
|
|
ttl: 300
|
|
|
|
value:
|
2020-07-28 06:44:33 -05:00
|
|
|
- "{{ inventory_hostname_short }}.{{ zone }}."
|
2020-06-30 05:52:18 -05:00
|
|
|
- name: Assure SRV record
|
|
|
|
route53:
|
|
|
|
state: present
|
2020-07-23 21:02:56 -05:00
|
|
|
overwrite: yes
|
2020-06-30 05:52:18 -05:00
|
|
|
zone: "{{ zone }}"
|
|
|
|
type: SRV
|
|
|
|
record: "_minecraft._tcp.{{ mcname }}.mc.{{ zone }}."
|
|
|
|
ttl: 300
|
|
|
|
value:
|
2020-07-28 06:44:33 -05:00
|
|
|
- "1 10 {{ mcport }} {{ inventory_hostname_short }}.{{ zone }}."
|
2020-02-24 00:18:41 -06:00
|
|
|
become: yes
|