minecraft multi-instance support

This commit is contained in:
Ryan Cavicchioni 2020-01-22 20:16:31 -06:00
parent 2b1ba0d6fc
commit b769ea477b
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
4 changed files with 39 additions and 84 deletions

View File

@ -14,3 +14,9 @@
service:
name: rsyslog
state: restarted
- name: restart minecraft instances
service:
name: "minecraft@{{ item.name }}.service"
state: restarted
loop: "{{ minecraft_worlds | default([]) }}"

View File

@ -37,13 +37,12 @@
- name: create minecraft var directory
file:
path: "{{ item }}"
path: "{{ minecraft_var_path }}/{{ item.name }}"
state: directory
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: "0755"
with_items:
- "{{ minecraft_var_path }}"
loop: "{{ minecraft_worlds }}"
- name: download minecraft server
get_url:
@ -53,29 +52,31 @@
group: "{{ minecraft_group }}"
mode: "0644"
checksum: "{{ minecraft_jar_checksum }}"
notify: restart minecraft
notify: restart minecraft instances
- name: agree to the eula
copy:
content: "eula=true"
dest: "{{ minecraft_var_path }}/eula.txt"
dest: "{{ minecraft_var_path }}/{{ item.name }}/eula.txt"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: "0644"
loop: "{{ minecraft_worlds }}"
- name: configure minecraft
template:
src: server.properties.j2
dest: "{{ minecraft_var_path }}/server.properties"
dest: "{{ minecraft_var_path }}/{{ item.name }}/server.properties"
owner: root
group: root
mode: 0644
notify: restart minecraft
notify: restart minecraft instances
loop: "{{ minecraft_worlds }}"
- name: configure systemd unit
template:
src: minecraft.service.j2
dest: /etc/systemd/system/minecraft.service
dest: /etc/systemd/system/minecraft@.service
owner: root
group: root
mode: 0644
@ -84,83 +85,30 @@
- name: manage minecraft service
service:
name: "{{ minecraft_service_name }}"
name: "minecraft@{{ item.name }}"
state: "{{ minecraft_service_state }}"
enabled: "{{ minecraft_service_enabled }}"
loop: "{{ minecraft_worlds }}"
- name: configure ops
copy:
content: "{{ (minecraft_ops | default([])) | to_nice_json }}"
dest: "{{ minecraft_var_path }}/ops.json"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: "0644"
force: no
notify: restart minecraft
- name: configure whitelist
copy:
content: "{{ (minecraft_whitelist | default([])) | to_nice_json }}"
dest: "{{ minecraft_var_path }}/whitelist.json"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: "0644"
force: no
notify: restart minecraft
- name: install backup script
copy:
src: minecraft-backup.sh
dest: "{{ minecraft_opt_path }}/bin/minecraft-backup"
owner: root
group: root
mode: 0700
- name: backup cron job
cron:
name: minecraft backup
minute: "0"
hour: "9"
user: root
job: "{{ minecraft_opt_path }}/bin/minecraft-backup"
- name: backup clean up cron
cron:
name: minecraft backup clean up
minute: "0"
hour: "11"
user: root
job: "find {{ minecraft_opt_path }}/backup/ -type f -name '*.tar.xz' -ctime +7 -delete"
- name: set world download password
htpasswd:
path: "{{ minecraft_opt_path }}/etc/htpasswd"
name: minecraft
password: minecraft
owner: root
group: root
mode: 0644
when: "'nginx' in ansible_play_role_names"
- name: configure nginx
template:
src: nginx.conf.j2
dest: /etc/nginx/sites-available/minecraft
owner: root
group: root
mode: 0644
when: "'nginx' in ansible_play_role_names"
notify: reload nginx
- name: activate site
file:
src: /etc/nginx/sites-available/minecraft
dest: /etc/nginx/sites-enabled/minecraft
owner: root
group: root
state: link
when: "'nginx' in ansible_play_role_names"
notify: reload nginx
#- name: configure ops
# copy:
# content: "{{ (minecraft_ops | default([])) | to_nice_json }}"
# dest: "{{ minecraft_var_path }}/ops.json"
# owner: "{{ minecraft_user }}"
# group: "{{ minecraft_group }}"
# mode: "0644"
# force: no
# notify: restart minecraft instances
#
#- name: configure whitelist
# copy:
# content: "{{ (minecraft_whitelist | default([])) | to_nice_json }}"
# dest: "{{ minecraft_var_path }}/whitelist.json"
# owner: "{{ minecraft_user }}"
# group: "{{ minecraft_group }}"
# mode: "0644"
# force: no
# notify: restart minecraft instances
- name: install discord notifier
copy:

View File

@ -1,7 +1,7 @@
# {{ ansible_managed }}
[Unit]
Description=Minecraft server
Description=Minecraft server %i
After=network.target
[Service]
@ -10,7 +10,7 @@ SuccessExitStatus=143
Type=simple
User={{ minecraft_user }}
Group={{ minecraft_group }}
WorkingDirectory={{ minecraft_var_path }}
WorkingDirectory={{ minecraft_var_path }}/%i
Restart=on-failure
SyslogIdentifier=minecraft
SyslogFacility={{ minecraft_syslog_facility }}

View File

@ -1,2 +1,3 @@
white-list: {{ (minecraft_config.whitelist | default(true)) | ternary('true', 'false') }}
enforce-whitelist: {{ (minecaft_config.enfoce_whitelist | default(true)) | ternary('true', 'false') }}
server-port: {{ item.port | default(25565) }}