ansible/roles/docker-minecraft/tasks/main.yml

59 lines
2.1 KiB
YAML

#!/usr/bin/env ansible-playbook
# vim:ft=ansible:
---
- name: assure minecraft {{ minecraft_name }} directory structure
file:
state: directory
owner: "{{ minecraft_uid }}"
group: "{{ minecraft_gid }}"
mode: "0750"
path: "{{ item }}"
# We recurse here since these directories *and all of their contents*
# should be read-write by the container without exception.
recurse: yes
with_items:
- "{{ minecraft_data_prefix }}/backups"
- "{{ minecraft_data_prefix }}/logs"
- "{{ minecraft_data_prefix }}/world"
- name: assure minecraft {{ minecraft_name }} files
file:
state: touch
owner: "{{ minecraft_uid }}"
group: "{{ minecraft_gid }}"
mode: "0640"
path: "{{ item }}"
with_items:
- "{{ minecraft_data_prefix }}/ops.json"
- "{{ minecraft_data_prefix }}/server.properties"
- name: assure {{ minecraft_name }} server properties
lineinfile:
state: present
regexp: "^{{ item.key }}"
line: "{{ item.key }}={{ item.value }}"
path: "{{ minecraft_data_prefix }}/server.properties"
with_dict: "{{ minecraft_server_properties }}"
notify: "restart minecraft {{ minecraft_name }}"
- name: assure minecraft {{ minecraft_name }} container
docker_container:
name: "minecraft-{{ minecraft_name }}"
state: "{{ minecraft_state }}"
image: "{{ minecraft_image }}"
restart_policy: "{{ minecraft_restart_policy }}"
pull: yes
user: "{{ minecraft_uid }}:{{ minecraft_gid }}"
env:
TZ: "{{ minecraft_timezone }}"
ARGS: "{{ minecraft_jvm_args }} {{ minecraft_jvm_extra_args }}"
JRE_XMX: "{{ minecraft_xmx }}"
JRE_XMS: "{{ minecraft_xms }}"
FORGE_PACK_ZIP: "{{ minecraft_pack_zip }}"
ports:
- "{{ minecraft_external_port }}:25565/tcp"
- "{{ minecraft_external_port }}:25565/udp"
volumes:
- "{{ minecraft_data_prefix }}/backups:/minecraft/backups"
- "{{ minecraft_data_prefix }}/logs:/minecraft/logs"
- "{{ minecraft_data_prefix }}/ops.json:/minecraft/ops.json"
- "{{ minecraft_data_prefix }}/server.properties:/minecraft/server.properties"
- "{{ minecraft_data_prefix }}/world:/minecraft/world"