initial commit

This commit is contained in:
2022-11-04 17:02:32 +01:00
commit 2bf26a8285
26 changed files with 438 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.idea/*

29
.travis.yml Normal file
View File

@@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

38
README.md Normal file
View File

@@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

9
defaults/main.yml Normal file
View File

@@ -0,0 +1,9 @@
---
ts3_version: "3.13.6"
ts3_user: "teamspeak"
ts3_user_home_dir: "/home/{{ ts3_user }}"
ts3_base_dir: "{{ ts3_user_home_dir }}/teamspeak3-server_linux_amd64"
ts3_install_service: true
ts3_installed_version: "0.0.0"
ts3_initial_installation: true

5
handlers/main.yml Normal file
View File

@@ -0,0 +1,5 @@
---
- name: "Reload systemd"
ansible.builtin.systemd:
daemon_reload: yes

52
meta/main.yml Normal file
View File

@@ -0,0 +1,52 @@
galaxy_info:
author: SecretMineDE
description: Sets up a ts3 server
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license:
min_ansible_version: 2.9
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@@ -0,0 +1,13 @@
---
- name: "Check Distribution"
ansible.builtin.assert:
that:
- "ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'"
- "ansible_architecture == 'x86_64'"
- name: "Install packages"
ansible.builtin.apt:
name:
- "rsync"
update_cache: "yes"

View File

@@ -0,0 +1,15 @@
---
- name: "Get latest version (raw)"
ansible.builtin.uri:
url: "https://www.teamspeak.com/versions/server.json"
method: GET
return_content: yes
status_code: 200
body_format: json
register: ts3_version_info
- name: "Extract relevant info from result"
ansible.builtin.set_fact:
ts3_version: "{{ ts3_version_info.json.linux.x86_64.version }}"
ts3_download_mirror: "{{ ts3_version_info.json.linux.x86_64.mirrors | first }}"

View File

@@ -0,0 +1,22 @@
---
- name: "Set download url for latest version"
ansible.builtin.set_fact:
ts3_download_url: "{{ ts3_version_info['json']['linux']['x86_64']['mirrors'][ts3_download_mirror] }}"
when:
- "ts3_version is defined"
- "ts3_version != 'latest'"
- "ts3_download_mirror is defined"
- name: "Set download url if version was specified"
ansible.builtin.set_fact:
ts3_download_url: "https://files.teamspeak-services.com/releases/server/{{ ts3_version }}/teamspeak3-server_linux_amd64-{{ ts3_version }}.tar.bz2"
when:
- "ts3_version != 'latest'"
- "ts3_download_url is undefined"
- name: "Assert gathered data is valid"
ansible.builtin.assert:
that:
- "ts3_version is defined"
- "ts3_version != 'latest'"
- "ts3_download_url is defined"

View File

@@ -0,0 +1,21 @@
---
- name: "check if version file exists"
ansible.builtin.stat:
path: "{{ ts3_base_dir }}/installed-version.txt"
register: ts3_installed_version_file
- name: "get installed version file"
ansible.builtin.slurp:
src: "{{ ts3_base_dir }}/installed-version.txt"
when:
- "ts3_installed_version_file.stat.exists"
register: ts3_installed_version_raw
- name: "set installed version"
ansible.builtin.set_fact:
ts3_installed_version: "{{ ts3_installed_version_raw.content | b64decode }}"
ts3_initial_installation: false
when:
- "ts3_installed_version_raw is defined"
- "ts3_installed_version_file.stat.exists"

7
tasks/10-user-setup.yml Normal file
View File

@@ -0,0 +1,7 @@
---
- name: "create system user"
ansible.builtin.user:
name: "{{ ts3_user }}"
shell: "/bin/false"
state: "present"

17
tasks/11-setup-dirs.yml Normal file
View File

@@ -0,0 +1,17 @@
- name: "Create directories"
ansible.builtin.file:
path: "{{ ts3_user_home_dir }}/{{ item }}"
state: "directory"
owner: "{{ ts3_user }}"
group: "{{ ts3_user }}"
loop:
- "temp"
- "backup"
- "teamspeak3-server_linux_amd64"
- name: "Create license accept file"
ansible.builtin.file:
path: "{{ ts3_base_dir }}/.ts3server_license_accepted"
state: "touch"
owner: "{{ ts3_user }}"
group: "{{ ts3_user }}"

0
tasks/20-backup.yml Normal file
View File

48
tasks/30-install-ts3.yml Normal file
View File

@@ -0,0 +1,48 @@
---
- name: "Create service"
ansible.builtin.template:
src: "teamspeak3.service.j2"
dest: "/etc/systemd/system/teamspeak3.service"
notify:
- "Reload systemd"
- name: "Stop service"
ansible.builtin.systemd:
name: "teamspeak3"
state: "stopped"
- name: "Download Archive for version {{ ts3_version }}"
ansible.builtin.get_url:
url: "{{ ts3_download_url }}"
dest: "{{ ts3_user_home_dir }}/temp/ts3-{{ ts3_version }}.tar.bz2"
owner: "{{ ts3_user }}"
group: "{{ ts3_user }}"
- name: "Extract archive"
ansible.builtin.unarchive:
src: "{{ ts3_user_home_dir }}/temp/ts3-{{ ts3_version }}.tar.bz2"
dest: "{{ ts3_user_home_dir }}/temp/"
remote_src: "yes"
owner: "{{ ts3_user }}"
group: "{{ ts3_user }}"
mode: "0700"
- name: "Install files"
ansible.posix.synchronize:
src: "{{ ts3_user_home_dir }}/temp/teamspeak3-server_linux_amd64/"
dest: "{{ ts3_base_dir }}/"
delegate_to: "{{ inventory_hostname }}"
- name: "Register installed version"
ansible.builtin.template:
src: "installed-version.txt.j2"
dest: "{{ ts3_base_dir }}/installed-version.txt"
owner: "{{ ts3_user }}"
group: "{{ ts3_user }}"
- name: "Remove temporary files"
ansible.builtin.file:
path: "{{ ts3_user_home_dir }}/temp/teamspeak3-server_linux_amd64/"
state: "absent"

View File

@@ -0,0 +1,41 @@
---
- name: "check if installed-file"
ansible.builtin.stat:
path: "{{ ts3_base_dir }}/.ts3_installed"
register: ts3_installed_file
- name: "Set query password"
when:
- "ts3_installed_file.stat.exists == false"
block:
- name: "Ensure parameter passing is enabled"
ansible.builtin.lineinfile:
path: "{{ ts3_base_dir }}/ts3server_startscript.sh"
regexp: '^COMMANDLINE_PARAMETERS='
line: 'COMMANDLINE_PARAMETERS="$2"'
- name: "Generate password"
ansible.builtin.set_fact:
ts3_query_password: "{{ lookup('ansible.builtin.password', '/dev/null chars=digits,ascii_letters length=32') }}"
- name: "Run teamspeak with modified password"
become: true
become_user: "{{ ts3_user }}"
shell:
cmd: "/bin/bash ts3server_startscript.sh start serveradmin_password={{ ts3_query_password }}"
chdir: "{{ ts3_base_dir }}"
- name: "Stop teamspeak"
become: true
become_user: "{{ ts3_user }}"
shell:
cmd: "/bin/bash ts3server_startscript.sh stop"
chdir: "{{ ts3_base_dir }}"
- name: "write tatoo file"
ansible.builtin.template:
src: "installed-version.txt.j2"
dest: "{{ ts3_base_dir }}/.ts3_installed"
owner: "{{ ts3_user }}"
group: "{{ ts3_user }}"

View File

@@ -0,0 +1,15 @@
---
- name: "Get Admin Token on first installation"
when: "ts3_initial_installation"
block:
- name: "get file content"
shell: "grep '|token=' {{ ts3_base_dir }}/logs/*.log"
register: ts3_log_content
- name: "search for token"
ansible.builtin.set_fact:
ts3_admin_token: "{{ item | regex_search('.*\\|token=(.*)$', '\\1') | first }}"
when:
- "'|token=' in item"
loop: "{{ ts3_log_content.stdout_lines }}"

View File

@@ -0,0 +1,7 @@
---
- name: "Start service"
ansible.builtin.systemd:
name: "teamspeak3"
state: "started"
enabled: "yes"

21
tasks/99-output.yml Normal file
View File

@@ -0,0 +1,21 @@
---
- name: "Write vars to file"
ansible.builtin.template:
src: "ts3_credentials.j2"
dest: "{{ ts3_base_dir }}/.ts3_credentials"
owner: "{{ ts3_user }}"
group: "{{ ts3_user }}"
mode: "0600"
when:
- "ts3_query_password is defined"
- "ts3_admin_token is defined"
- name: "Print Query Password"
debug:
msg: "Query password: {{ ts3_query_password }}"
when: "ts3_query_password is defined"
- name: "Print Admin Token"
debug:
msg: "Serveradmin Token: {{ ts3_admin_token }}"
when: "ts3_admin_token is defined"

44
tasks/main.yml Normal file
View File

@@ -0,0 +1,44 @@
---
- name: "Setup requirements"
include_tasks: "00-check-requirements.yml"
- name: "run version tasks"
include_tasks: "00-get-latest-version.yml"
when:
- "ts3_version == 'latest'"
- name: "Set download url"
include_tasks: "01-set-download-url.yml"
- name: "Get info of installed instance"
include_tasks: "02-get-installed-version.yml"
- name: "Setup system"
include_tasks: "{{ tasks_file }}"
loop_control:
loop_var: "tasks_file"
loop:
- "10-user-setup.yml"
- "11-setup-dirs.yml"
- debug:
var: ts3_version
- debug:
var: ts3_installed_version
- name: "Install TS3 {{ ts3_version }}"
include_tasks: "{{ tasks_file }}"
loop_control:
loop_var: "tasks_file"
loop:
- "30-install-ts3.yml"
- "31-set-query-password.yml"
- "32-get-admin-token.yml"
when:
- "ts3_installed_version is version(ts3_version, '<')"
- name: "Start Service"
include_tasks: "33-start-service.yml"
- name: "Show output"
include_tasks: "99-output.yml"

View File

@@ -0,0 +1 @@
{{ ts3_version }}

View File

@@ -0,0 +1,17 @@
[Unit]
Description=TeamSpeak3-Server
After=network.service
[Service]
User={{ ts3_user }}
Group={{ ts3_user }}
Type=forking
WorkingDirectory={{ ts3_base_dir }}/
ExecStart={{ ts3_base_dir }}/ts3server_startscript.sh start
ExecStop={{ ts3_base_dir }}/ts3server_startscript.sh stop
PIDFile={{ ts3_base_dir }}/ts3server.pid
RestartSec=5
Restart=always
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,5 @@
Query-Password:
{{ ts3_query_password }}
Admin-Token:
{{ ts3_admin_token }}

View File

@@ -0,0 +1 @@
{{ ts3_version }}

2
tests/inventory Normal file
View File

@@ -0,0 +1,2 @@
localhost

5
tests/test.yml Normal file
View File

@@ -0,0 +1,5 @@
---
- hosts: all
remote_user: root
roles:
- Ansible-Role-TeamSpeak3

2
vars/main.yml Normal file
View File

@@ -0,0 +1,2 @@
---
# vars file for .