129 lines
3.7 KiB
YAML
129 lines
3.7 KiB
YAML
#!/usr/bin/ansible-playbook
|
|
# vim:ft=ansible:
|
|
---
|
|
- name: Set up Terraria user
|
|
block:
|
|
- name: Install required packages
|
|
apt:
|
|
name:
|
|
- mono-complete
|
|
- name: Disable bundled services
|
|
systemd:
|
|
name: "{{ item }}"
|
|
enabled: no
|
|
state: stopped
|
|
loop:
|
|
- "mono-xsp4"
|
|
- name: Assure terraria admin group
|
|
group:
|
|
name: ter-admin
|
|
- name: Assure server user
|
|
user:
|
|
name: terraria
|
|
group: ter-admin
|
|
system: yes
|
|
home: "{{ terraria_root }}"
|
|
- name: Assure var directory
|
|
file:
|
|
path: "{{ terraria_root }}"
|
|
state: directory
|
|
owner: root
|
|
group: ter-admin
|
|
# Sticky, SetGID
|
|
mode: "3770"
|
|
- name: Assure systemd unit
|
|
template:
|
|
src: "tmodloader@.service"
|
|
dest: "/etc/systemd/system/tmodloader@.service"
|
|
- name: Reload available daemons
|
|
systemd:
|
|
daemon_reload: yes
|
|
become: yes
|
|
- name: Set up Terraria server
|
|
block:
|
|
- name: Create server directory
|
|
file:
|
|
path: "{{ terraria_root }}/{{ terraria_name }}"
|
|
state: directory
|
|
- name: Check for existing install
|
|
stat:
|
|
path: "{{ terraria_root }}/{{ terraria_name }}/tModLoaderServer"
|
|
register: stat_server_binary
|
|
- name: Unpack archive
|
|
block:
|
|
- name: Download tarball
|
|
get_url:
|
|
dest: "{{ terraria_root }}/{{ terraria_name }}/pack.tgz"
|
|
url: "{{ terraria_tarball }}"
|
|
- name: Unpack tarball
|
|
unarchive:
|
|
src: "{{ terraria_root }}/{{ terraria_name }}/pack.tgz"
|
|
remote_src: yes
|
|
dest: "{{ terraria_root }}/{{ terraria_name }}"
|
|
- name: Mark executable
|
|
file:
|
|
path: "{{ terraria_root }}/{{ terraria_name }}/tModLoaderServer.bin.x86_64"
|
|
mode: "0755"
|
|
- name: Clean up
|
|
file:
|
|
path: "{{ item }}"
|
|
state: absent
|
|
loop:
|
|
- "{{ terraria_root }}/{{ terraria_name }}/pack.tgz"
|
|
- name: Create worlds directory
|
|
file:
|
|
path: "{{ terraria_root }}/{{ terraria_name }}/worlds"
|
|
owner: terraria
|
|
group: ter-admin
|
|
state: directory
|
|
- name: Fix ownership
|
|
file:
|
|
path: "{{ terraria_root }}/{{ terraria_name }}"
|
|
recurse: yes
|
|
owner: terraria
|
|
group: ter-admin
|
|
when: not stat_server_binary.stat.exists
|
|
- name: Configure server
|
|
block:
|
|
- name: Template out server config
|
|
template:
|
|
src: config
|
|
dest: "{{ terraria_root }}/{{ terraria_name }}/config"
|
|
owner: terraria
|
|
group: ter-admin
|
|
become: yes
|
|
- name: Set up backups
|
|
block:
|
|
- name: Create backups directory
|
|
file:
|
|
state: directory
|
|
mode: "0770"
|
|
path: "{{ terraria_root }}/{{ terraria_name }}/backups"
|
|
owner: terraria
|
|
group: ter-admin
|
|
- name: Template out backup script
|
|
template:
|
|
src: "backup.sh"
|
|
dest: "{{ terraria_root }}/{{ terraria_name }}/backup.sh"
|
|
owner: terraria
|
|
group: ter-admin
|
|
mode: "0700"
|
|
- name: Template out nightly backup script
|
|
template:
|
|
src: "backup-nightly.sh"
|
|
dest: "/opt/backups/modules/tmodloader-{{ terraria_name }}.sh"
|
|
mode: "0600"
|
|
- name: Set up backup cronjob
|
|
cron:
|
|
minute: "*/30"
|
|
name: "ansible-backup-terraria-{{ terraria_name }}"
|
|
job: "{{ terraria_root }}/{{ terraria_name }}/backup.sh >> {{ terraria_root }}/{{ terraria_name }}/backups.log 2>&1"
|
|
become: yes
|
|
- name: Enable service
|
|
systemd:
|
|
name: "tmodloader@{{ terraria_name }}"
|
|
daemon_reload: yes
|
|
enabled: yes
|
|
state: started
|
|
become: yes
|