#!/usr/bin/env ansible-playbook # vim:ft=ansible: --- - name: set up system block: - name: install required packages apt: name="{{ terraria_packages + terraria_packages_extra }}" - name: assure server user user: name=terraria system=yes home={{ terraria_home }} - name: assure operational directory file: path={{ terraria_home }} state=directory owner=terraria group=terraria mode="3775" - name: assure systemd unit template: src=terraria@.service dest=/etc/systemd/system/terraria@.service notify: "restart terraria {{ terraria_name }}" - name: set up terraria block: - name: assure server directory file: path={{ terraria_home }}/{{ terraria_name }} state=directory - name: download server zip get_url: url={{ terraria_downloadurl }} dest={{ terraria_home }}/{{ terraria_name }}/server.zip register: download_server - name: install server block: - name: assure server unzip directory file: path={{ terraria_home }}/{{ terraria_name }}/server state=directory - name: unpack zip unarchive: src={{ terraria_home }}/{{ terraria_name }}/server.zip dest={{ terraria_home }}/{{ terraria_name }}/server remote_src=yes - name: template out installer template: src=install-server.sh dest={{ terraria_home }}/{{ terraria_name }}/install-server.sh - name: run installer command: chdir: "{{ terraria_home }}/{{ terraria_name }}" argv: [ "bash", "./install-server.sh" ] notify: "restart terraria {{ terraria_name }}" when: download_server is changed - name: configure server settings lineinfile: dest: "{{ terraria_home }}/{{ terraria_name }}/config" line: "{{ item.key }}={{ item.value }}" regex: "^{{ item.key }}=.*" create: yes with_dict: "{{ terraria_config_default | combine(terraria_config) }}" notify: "restart terraria {{ terraria_name }}" become: yes become_user: terraria - name: enable service systemd: name=terraria@{{ terraria_name }}.service enabled=yes state=started when: terraria_enabled - name: disable service systemd: name=terraria@{{ terraria_name }}.service enabled=no state=stopped when: not terraria_enabled