2022-06-14 18:25:02 -05:00
|
|
|
#!/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:
|
2022-06-14 18:25:02 -05:00
|
|
|
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"
|
2023-03-10 19:21:00 -06:00
|
|
|
- "{{ tmodloader_data_prefix }}/logs"
|
2022-06-14 18:25:02 -05:00
|
|
|
- name: assure mods
|
2022-06-16 23:45:29 -05:00
|
|
|
ansible.builtin.shell:
|
2022-06-14 18:25:02 -05:00
|
|
|
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
|
2022-06-14 18:25:02 -05:00
|
|
|
notify: "restart tmodloader {{ tmodloader_name }}"
|
|
|
|
- name: enable mods
|
2022-06-16 23:45:29 -05:00
|
|
|
ansible.builtin.template:
|
2022-06-14 18:25:02 -05:00
|
|
|
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
|
2022-06-14 18:25:02 -05:00
|
|
|
notify: "restart tmodloader {{ tmodloader_name }}"
|
|
|
|
- name: assure tmodloader {{ tmodloader_name }} files
|
2022-06-16 23:45:29 -05:00
|
|
|
ansible.builtin.file:
|
2022-06-14 18:25:02 -05:00
|
|
|
state: touch
|
|
|
|
owner: "{{ tmodloader_uid }}"
|
|
|
|
group: "{{ tmodloader_gid }}"
|
2022-06-16 23:45:29 -05:00
|
|
|
mode: "0750"
|
2022-06-14 18:25:02 -05:00
|
|
|
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:
|
2022-06-14 18:25:02 -05:00
|
|
|
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:
|
2022-06-14 18:25:02 -05:00
|
|
|
user: root
|
|
|
|
name: "terraria-{{ tmodloader_name }}"
|
|
|
|
minute: "*/30"
|
2023-03-10 19:28:46 -06:00
|
|
|
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\""
|
2022-06-14 18:25:02 -05:00
|
|
|
- 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"
|
2023-03-10 19:21:00 -06:00
|
|
|
- "{{ tmodloader_data_prefix }}/logs:/terraria-server/tModLoader-Logs"
|