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

77 lines
3.0 KiB
YAML
Raw Normal View History

#!/usr/bin/env ansible-playbook
# vim:ft=ansible:
---
- name: assure tmodloader {{ tmodloader_name }} directory structure
2022-06-16 23:45:29 -05:00
ansible.builtin.file:
state: directory
owner: "{{ tmodloader_uid }}"
group: "{{ tmodloader_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:
- "{{ tmodloader_data_prefix }}/backups"
- "{{ tmodloader_data_prefix }}/data"
- "{{ tmodloader_data_prefix }}/data/ModLoader"
- "{{ tmodloader_data_prefix }}/data/ModLoader/Mods"
- "{{ tmodloader_data_prefix }}/data/ModLoader/Worlds"
- "{{ tmodloader_data_prefix }}/logs"
- name: assure mods
2022-06-16 23:45:29 -05:00
ansible.builtin.shell:
cmd: "curl -L \"{{ tmodloader_mod_server }}\" -o \"{{ item }}.tmod\" && chown \"{{ tmodloader_uid }}:{{ tmodloader_gid }}\" \"{{ item }}.tmod\""
chdir: "{{ tmodloader_data_prefix }}/data/ModLoader/Mods"
creates: "{{ tmodloader_data_prefix }}/data/ModLoader/Mods/{{ item }}.tmod"
with_list: "{{ tmodloader_mods }}"
2023-12-23 13:25:49 -06:00
when: tmodloader_mods
notify: "restart tmodloader {{ tmodloader_name }}"
- name: enable mods
2022-06-16 23:45:29 -05:00
ansible.builtin.template:
src: enabled.json
dest: "{{ tmodloader_data_prefix }}/data/ModLoader/Mods/enabled.json"
owner: "{{ tmodloader_uid }}"
group: "{{ tmodloader_gid }}"
2022-06-16 23:45:29 -05:00
mode: "0750"
2023-12-23 13:25:49 -06:00
when: tmodloader_mods
notify: "restart tmodloader {{ tmodloader_name }}"
- name: assure tmodloader {{ tmodloader_name }} files
2022-06-16 23:45:29 -05:00
ansible.builtin.file:
state: touch
owner: "{{ tmodloader_uid }}"
group: "{{ tmodloader_gid }}"
2022-06-16 23:45:29 -05:00
mode: "0750"
path: "{{ item }}"
with_items:
- "{{ tmodloader_data_prefix }}/config.txt"
- name: assure {{ tmodloader_name }} configs
2022-06-16 23:45:29 -05:00
ansible.builtin.lineinfile:
state: present
regexp: "^{{ item.key }}"
line: "{{ item.key }}={{ item.value }}"
path: "{{ tmodloader_data_prefix }}/config.txt"
with_dict: "{{ tmodloader_config | combine(tmodloader_config_extra) | combine(tmodloader_config_internal) }}"
notify: "restart tmodloader {{ tmodloader_name }}"
- name: assure {{ tmodloader_name }} backup cronjob
2022-06-16 23:45:29 -05:00
ansible.builtin.cron:
user: root
name: "terraria-{{ tmodloader_name }}"
minute: "*/30"
job: "tar czvf \"{{ tmodloader_data_prefix }}/backups/world-$(date +%Y-%m-%d-%H%M).tgz\" \"{{ tmodloader_data_prefix }}/data/ModLoader/Worlds\" \"{{ tmodloader_data_prefix }}/data/tModLoader/Worlds\""
- name: assure tmodloader {{ tmodloader_name }} container
docker_container:
name: "tmodloader-{{ tmodloader_name }}"
state: started
image: "{{ tmodloader_image }}"
restart_policy: "{{ tmodloader_restart_policy }}"
pull: yes
user: "{{ tmodloader_uid }}:{{ tmodloader_gid }}"
env:
TZ: "{{ tmodloader_timezone }}"
ports:
- "{{ tmodloader_external_port }}:7777"
volumes:
- "{{ tmodloader_data_prefix }}/data:/terraria"
- "{{ tmodloader_data_prefix }}/config.txt:/terraria/config.txt"
- "{{ tmodloader_data_prefix }}/logs:/terraria-server/tModLoader-Logs"