Rework Terraria deployments into a role, too

This commit is contained in:
Salt 2022-06-14 18:25:02 -05:00
parent 2a8b8669ac
commit 784a730152
5 changed files with 146 additions and 6 deletions

View File

@ -28,13 +28,28 @@
tags: [ backup ]
- hosts: vm-terraria-1.home.mgmt.desu.ltd
gather_facts: no
pre_tasks:
- name: include tasks for gameservers
include_tasks: tasks/game/{{ item }}
with_items:
- terraria-thorium.yml
tags: [ always ]
roles:
- role: docker-tmodloader13
vars:
tmodloader_name: thorium
tmodloader_mods:
- ThoriumMod
- BossChecklist
- MagicStorageExtra
- SmartDoors
- SummonersAssociation
- VeinMiner
- Unleveled
- FKBossHealthBar
- ZoomOut
- AlchemistNPC
- BossCursor
- Bags_To_Money
- WingSlot
- StarsAbove
- SubworldLibrary
- StarsAboveMusic
tags: [ tmodloader, terraria ]
- role: backup
vars:
backup_s3backup_list_extra:

View File

@ -0,0 +1,41 @@
#!/usr/bin/env ansible-playbook
# vim:ft=ansible:
tmodloader_name: generic
# Container settings
tmodloader_uid: 1521
tmodloader_gid: 1521
tmodloader_state: started
tmodloader_image: rehashedsalt/tmodloader-docker:bleeding
tmodloader_restart_policy: unless-stopped
tmodloader_timezone: "America/Chicago"
# Container network settings
tmodloader_external_port: "7777"
tmodloader_data_prefix: "/data/terraria/{{ tmodloader_name }}"
# Server configuration
# We have two variables here; things you might not want to change and things
# that you probably will
tmodloader_config:
autocreate: "3"
difficulty: "1"
secure: "0"
tmodloader_config_extra:
maxplayers: "8"
motd: "Deployed via Ansible edition"
password: "dicks"
# Server configuration specific to this Ansible role
# DO NOT CHANGE
tmodloader_config_internal:
port: "7777"
world: "/terraria/ModLoader/Worlds/World.wld"
worldpath: "/terraria/ModLoader/Worlds"
# A list of mods to acquire
# The default server of mirror.sgkoi.dev is the official tModLoader mod browser
# mirror
tmodloader_mod_server: "https://mirror.sgkoi.dev"
# tmodloader_mods:
# - "CalamityMod"
# - "RecipeBrowser"
# - "BossChecklist"
tmodloader_mods: []

View File

@ -0,0 +1,7 @@
#!/usr/bin/env ansible-playbook
# vim:ft=ansible:
- name: restart tmodloader {{ tmodloader_name }}
docker_container:
name: "tmodloader-{{ tmodloader_name }}"
state: started
restart: yes

View File

@ -0,0 +1,71 @@
#!/usr/bin/env ansible-playbook
# vim:ft=ansible:
---
- name: assure tmodloader {{ tmodloader_name }} directory structure
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"
- name: assure mods
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 }}"
notify: "restart tmodloader {{ tmodloader_name }}"
- name: enable mods
template:
src: enabled.json
dest: "{{ tmodloader_data_prefix }}/data/ModLoader/Mods/enabled.json"
owner: "{{ tmodloader_uid }}"
group: "{{ tmodloader_gid }}"
notify: "restart tmodloader {{ tmodloader_name }}"
- name: assure tmodloader {{ tmodloader_name }} files
file:
state: touch
owner: "{{ tmodloader_uid }}"
group: "{{ tmodloader_gid }}"
mode: "0640"
path: "{{ item }}"
with_items:
- "{{ tmodloader_data_prefix }}/config.txt"
- name: assure {{ tmodloader_name }} configs
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
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\""
- 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"

View File

@ -0,0 +1,6 @@
[
{% for item in tmodloader_mods[1:] %}
"{{ item }}",
{% endfor %}
"{{ tmodloader_mods[0] }}"
]