minecraft/server/tasks/main.yaml
changeset 156 ebd8a21a0e62
parent 155 4d45841961e7
child 162 a7a64ed07204
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/minecraft/server/tasks/main.yaml	Sat Jul 03 13:23:46 2021 -0500
@@ -0,0 +1,90 @@
+---
+
+- name: add minecraft user
+  become: yes
+  user: name="{{minecraft_user}}" home="{{minecraft_dir}}"
+
+- name: install adoptopenjdk
+  include_tasks: adoptopenjdk.yaml
+
+- name: set minecraft fork
+  set_fact: minecraft_url="{{minecraft_vanilla_url}}"
+  when: minecraft_fork == "vanilla"
+
+- name: set minecraft fork
+  set_fact: minecraft_url="{{minecraft_paper_url}}"
+  when: minecraft_fork == "paper"
+
+- name: create minecraft dir
+  become: yes
+  file:
+    path: "{{minecraft_dir}}"
+    owner: "{{minecraft_user}}"
+    group: "{{minecraft_user}}"
+    mode: "0755"
+    state: "directory"
+
+- name: download minecraft
+  become: yes
+  get_url:
+    url: "{{minecraft_url}}"
+    dest: "{{minecraft_dir}}/server.jar"
+    mode: "0755"
+  notify: restart minecraft
+
+- name: configure minecraft eula
+  become: yes
+  copy:
+    src: "{{item}}"
+    dest: "{{minecraft_dir}}/{{item}}"
+    owner: "{{minecraft_user}}"
+    group: "{{minecraft_user}}"
+  loop:
+    - "eula.txt"
+  notify: restart minecraft
+
+- name: configure minecraft ops
+  become: yes
+  template:
+    src: "ops.json.j2"
+    dest: "{{minecraft_dir}}/ops.json"
+    owner: "{{minecraft_user}}"
+    group: "{{minecraft_user}}"
+  notify: restart minecraft
+
+- name: install plugins
+  include_tasks: dynmap.yaml
+  when: minecraft_fork == "paper"
+
+- name: create server.properties
+  become: yes
+  file:
+    path: "{{minecraft_dir}}/server.properties"
+    state: "touch"
+    access_time: "preserve"
+    modification_time: "preserve"
+    owner: "{{minecraft_user}}"
+    group: "{{minecraft_user}}"
+
+- name: configure server.properties
+  become: yes
+  lineinfile:
+    path: "{{minecraft_dir}}/server.properties"
+    regexp: "^{{item.key}}="
+    line: "{{item.key}}={{item.value}}"
+  notify: restart minecraft
+  loop:
+    - {key: "motd", value: "{{minecraft_motd}}"}
+    - {key: "level-seed", value: "{{minecraft_seed}}"}
+    - {key: "difficulty", value: "{{minecraft_difficulty}}"}
+
+- name: install systemd service
+  become: yes
+  template:
+    src: "minecraft.service.j2"
+    dest: "/lib/systemd/system/minecraft.service"
+  notify: restart minecraft
+
+- name: ensure service is started
+  become: yes
+  systemd: name="minecraft.service" enabled="yes" state="started"