From 784a7301526fe93156f4b14321220d4fe10f0df6 Mon Sep 17 00:00:00 2001 From: Salt Date: Tue, 14 Jun 2022 18:25:02 -0500 Subject: [PATCH] Rework Terraria deployments into a role, too --- playbooks/home_game.yml | 27 +++++-- roles/docker-tmodloader13/defaults/main.yml | 41 +++++++++++ roles/docker-tmodloader13/handlers/main.yml | 7 ++ roles/docker-tmodloader13/tasks/main.yml | 71 +++++++++++++++++++ .../templates/enabled.json | 6 ++ 5 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 roles/docker-tmodloader13/defaults/main.yml create mode 100644 roles/docker-tmodloader13/handlers/main.yml create mode 100644 roles/docker-tmodloader13/tasks/main.yml create mode 100644 roles/docker-tmodloader13/templates/enabled.json diff --git a/playbooks/home_game.yml b/playbooks/home_game.yml index cc15735..9f83674 100755 --- a/playbooks/home_game.yml +++ b/playbooks/home_game.yml @@ -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: diff --git a/roles/docker-tmodloader13/defaults/main.yml b/roles/docker-tmodloader13/defaults/main.yml new file mode 100644 index 0000000..9a82761 --- /dev/null +++ b/roles/docker-tmodloader13/defaults/main.yml @@ -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: [] diff --git a/roles/docker-tmodloader13/handlers/main.yml b/roles/docker-tmodloader13/handlers/main.yml new file mode 100644 index 0000000..d1680ca --- /dev/null +++ b/roles/docker-tmodloader13/handlers/main.yml @@ -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 diff --git a/roles/docker-tmodloader13/tasks/main.yml b/roles/docker-tmodloader13/tasks/main.yml new file mode 100644 index 0000000..920f7f4 --- /dev/null +++ b/roles/docker-tmodloader13/tasks/main.yml @@ -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" diff --git a/roles/docker-tmodloader13/templates/enabled.json b/roles/docker-tmodloader13/templates/enabled.json new file mode 100644 index 0000000..e5feb91 --- /dev/null +++ b/roles/docker-tmodloader13/templates/enabled.json @@ -0,0 +1,6 @@ +[ + {% for item in tmodloader_mods[1:] %} + "{{ item }}", + {% endfor %} + "{{ tmodloader_mods[0] }}" +]