ansible/roles/minecraft/tasks/main.yaml

149 lines
4.1 KiB
YAML
Raw Normal View History

2019-10-05 21:41:47 +00:00
---
- name: create minecraft group
group:
name: "{{ minecraft_group }}"
gid: "{{ minecraft_group_gid | default(omit) }}"
state: "{{ minecraft_group_state | default('present') }}"
system: yes
- name: create minecraft user
user:
name: "{{ minecraft_user }}"
uid: "{{ minecraft_user_uid | default(omit) }}"
group: "{{ minecraft_group }}"
home: "{{ minecraft_var_path }}"
create_home: no
shell: "{{ minecraft_shell | default('/usr/sbin/nologin') }}"
state: "{{ minecraft_user_state | default('present') }}"
system: yes
- name: install java
package:
name: "{{ minecraft_java_package_name }}"
state: "{{ minecraft_java_package_state }}"
- name: create minecraft installation directory
file:
path: "{{ item }}"
state: directory
owner: root
group: root
mode: "0755"
with_items:
- "{{ minecraft_opt_path }}"
- "{{ minecraft_opt_path }}/bin"
- "{{ minecraft_opt_path }}/etc"
2019-10-27 23:36:54 +00:00
- "{{ minecraft_opt_path }}/backup"
2019-10-05 21:41:47 +00:00
- name: create minecraft var directory
file:
2020-01-23 02:16:31 +00:00
path: "{{ minecraft_var_path }}/{{ item.name }}"
2019-10-05 21:41:47 +00:00
state: directory
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: "0755"
2020-01-23 02:16:31 +00:00
loop: "{{ minecraft_worlds }}"
2019-10-05 21:41:47 +00:00
- name: download minecraft server
get_url:
url: "{{ minecraft_jar_url }}"
dest: "{{ minecraft_opt_path }}/bin/server.jar"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: "0644"
2019-12-11 02:42:43 +00:00
checksum: "{{ minecraft_jar_checksum }}"
2020-01-23 02:16:31 +00:00
notify: restart minecraft instances
2019-10-05 21:41:47 +00:00
- name: agree to the eula
copy:
content: "eula=true"
2020-01-23 02:16:31 +00:00
dest: "{{ minecraft_var_path }}/{{ item.name }}/eula.txt"
2019-10-05 21:41:47 +00:00
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: "0644"
2020-01-23 02:16:31 +00:00
loop: "{{ minecraft_worlds }}"
2019-10-05 21:41:47 +00:00
- name: configure minecraft
template:
src: server.properties.j2
2020-01-23 02:16:31 +00:00
dest: "{{ minecraft_var_path }}/{{ item.name }}/server.properties"
2019-10-05 21:41:47 +00:00
owner: root
group: root
mode: 0644
2020-01-23 02:16:31 +00:00
notify: restart minecraft instances
loop: "{{ minecraft_worlds }}"
2019-10-05 21:41:47 +00:00
- name: configure systemd unit
template:
src: minecraft.service.j2
2020-01-23 02:16:31 +00:00
dest: /etc/systemd/system/minecraft@.service
2019-10-05 21:41:47 +00:00
owner: root
group: root
mode: 0644
#validate: systemd-analyze verify %s
notify: minecraft daemon-reload
- name: manage minecraft service
service:
2020-01-23 02:16:31 +00:00
name: "minecraft@{{ item.name }}"
2020-01-26 21:18:17 +00:00
state: "{{ item.state | default(minecraft_service_state) }}"
enabled: "{{ item.enabled | default(minecraft_service_enabled) }}"
2020-01-23 02:16:31 +00:00
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 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:
src: minecraft-discord.py
dest: "{{ minecraft_opt_path }}/bin/minecraft-discord"
owner: root
group: root
mode: 0755
notify: restart rsyslog
- name: configure discord notifier
copy:
dest: "{{ minecraft_opt_path }}/etc/discord.cfg"
owner: syslog
group: syslog
mode: 0600
content: "{% for k, v in minecraft_discord_config.items() %}{{ k }}={{ v }}{{ \"\n\" }}{% endfor %}"
notify: restart rsyslog
- name: configure rsyslog program
template:
src: rsyslog/minecraft.conf.j2
dest: /etc/rsyslog.d/05-minecraft.conf
owner: root
group: root
mode: 0644
notify: restart rsyslog
- name: manage rsyslog configuration
file:
path: "{{ item }}"
state: "{{ (minecraft_notifier_state == 'present') | ternary('file', 'absent') }}"
loop:
- /etc/rsyslog.d/05-minecraft.conf
- "{{ minecraft_opt_path }}/etc/discord.cfg"
- "{{ minecraft_opt_path }}/bin/minecraft-discord"
notify: restart rsyslog