Compare commits

..

2 Commits

Author SHA1 Message Date
b769ea477b
minecraft multi-instance support 2020-01-22 20:16:31 -06:00
2b1ba0d6fc
upgrade minecraft 2020-01-22 20:16:00 -06:00
5 changed files with 41 additions and 86 deletions

View File

@ -11,8 +11,8 @@ minecraft_port: 25565
minecraft_user: minecraft minecraft_user: minecraft
minecraft_group: minecraft minecraft_group: minecraft
minecraft_jar_url: https://launcher.mojang.com/v1/objects/4d1826eebac84847c71a77f9349cc22afd0cf0a1/server.jar minecraft_jar_url: https://launcher.mojang.com/v1/objects/bb2b6b1aefcd70dfd1892149ac3a215f6c636b07/server.jar
minecraft_jar_checksum: sha256:a0c062686bee5a92d60802ca74d198548481802193a70dda6d5fe7ecb7207993 minecraft_jar_checksum: sha256:80cf86dc2004ec6a2dc0183d1c75a9af3ba0669f7c332e4247afb1d76fb67e8a
minecraft_opt_path: /opt/minecraft minecraft_opt_path: /opt/minecraft
minecraft_var_path: "{{ minecraft_opt_path }}/var" minecraft_var_path: "{{ minecraft_opt_path }}/var"

View File

@ -14,3 +14,9 @@
service: service:
name: rsyslog name: rsyslog
state: restarted 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 - name: create minecraft var directory
file: file:
path: "{{ item }}" path: "{{ minecraft_var_path }}/{{ item.name }}"
state: directory state: directory
owner: "{{ minecraft_user }}" owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}" group: "{{ minecraft_group }}"
mode: "0755" mode: "0755"
with_items: loop: "{{ minecraft_worlds }}"
- "{{ minecraft_var_path }}"
- name: download minecraft server - name: download minecraft server
get_url: get_url:
@ -53,29 +52,31 @@
group: "{{ minecraft_group }}" group: "{{ minecraft_group }}"
mode: "0644" mode: "0644"
checksum: "{{ minecraft_jar_checksum }}" checksum: "{{ minecraft_jar_checksum }}"
notify: restart minecraft notify: restart minecraft instances
- name: agree to the eula - name: agree to the eula
copy: copy:
content: "eula=true" content: "eula=true"
dest: "{{ minecraft_var_path }}/eula.txt" dest: "{{ minecraft_var_path }}/{{ item.name }}/eula.txt"
owner: "{{ minecraft_user }}" owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}" group: "{{ minecraft_group }}"
mode: "0644" mode: "0644"
loop: "{{ minecraft_worlds }}"
- name: configure minecraft - name: configure minecraft
template: template:
src: server.properties.j2 src: server.properties.j2
dest: "{{ minecraft_var_path }}/server.properties" dest: "{{ minecraft_var_path }}/{{ item.name }}/server.properties"
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
notify: restart minecraft notify: restart minecraft instances
loop: "{{ minecraft_worlds }}"
- name: configure systemd unit - name: configure systemd unit
template: template:
src: minecraft.service.j2 src: minecraft.service.j2
dest: /etc/systemd/system/minecraft.service dest: /etc/systemd/system/minecraft@.service
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
@ -84,83 +85,30 @@
- name: manage minecraft service - name: manage minecraft service
service: service:
name: "{{ minecraft_service_name }}" name: "minecraft@{{ item.name }}"
state: "{{ minecraft_service_state }}" state: "{{ minecraft_service_state }}"
enabled: "{{ minecraft_service_enabled }}" enabled: "{{ minecraft_service_enabled }}"
loop: "{{ minecraft_worlds }}"
- name: configure ops #- name: configure ops
copy: # copy:
content: "{{ (minecraft_ops | default([])) | to_nice_json }}" # content: "{{ (minecraft_ops | default([])) | to_nice_json }}"
dest: "{{ minecraft_var_path }}/ops.json" # dest: "{{ minecraft_var_path }}/ops.json"
owner: "{{ minecraft_user }}" # owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}" # group: "{{ minecraft_group }}"
mode: "0644" # mode: "0644"
force: no # force: no
notify: restart minecraft # notify: restart minecraft instances
#
- name: configure whitelist #- name: configure whitelist
copy: # copy:
content: "{{ (minecraft_whitelist | default([])) | to_nice_json }}" # content: "{{ (minecraft_whitelist | default([])) | to_nice_json }}"
dest: "{{ minecraft_var_path }}/whitelist.json" # dest: "{{ minecraft_var_path }}/whitelist.json"
owner: "{{ minecraft_user }}" # owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}" # group: "{{ minecraft_group }}"
mode: "0644" # mode: "0644"
force: no # force: no
notify: restart minecraft # notify: restart minecraft instances
- 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: install discord notifier - name: install discord notifier
copy: copy:

View File

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

View File

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