diff --git a/roles/teamspeak_fallback/files/docker-compose.yml b/roles/teamspeak_fallback/files/docker-compose.yml deleted file mode 100644 index 06a7132..0000000 --- a/roles/teamspeak_fallback/files/docker-compose.yml +++ /dev/null @@ -1,19 +0,0 @@ -services: - teamspeak: - image: teamspeak - restart: always - ports: - - 9987:9987/udp - - 10011:10011 - - 30033:30033 - environment: - TS3SERVER_DB_PLUGIN: ts3db_sqlite3 - TS3SERVER_DB_SQLCREATEPATH: create_sqlite - TS3SERVER_LICENSE: accept - volumes: - - data:/var/ts3server/ - -volumes: - data: - external: true - name: teamspeak_fallback_data diff --git a/roles/webhook/files/teamspeak-fallback-db b/roles/teamspeak_fallback/files/teamspeak-fallback-db similarity index 100% rename from roles/webhook/files/teamspeak-fallback-db rename to roles/teamspeak_fallback/files/teamspeak-fallback-db diff --git a/roles/teamspeak_fallback/tasks/main.yml b/roles/teamspeak_fallback/tasks/main.yml index 9aae8c9..e2c70af 100644 --- a/roles/teamspeak_fallback/tasks/main.yml +++ b/roles/teamspeak_fallback/tasks/main.yml @@ -5,15 +5,12 @@ - name: Deploy {{ svc.name }} vars: svc: "{{ teamspeak_fallback_svc }}" + compose: "{{ teamspeak_fallback_compose }}" + env: "{{ teamspeak_fallback_env }}" + yml: "{{ teamspeak_fallback_yml }}" block: - - name: Import tasks to create service directory - ansible.builtin.import_tasks: tasks/steps/create-service-directory.yml - - - name: Copy the docker-compose file - ansible.builtin.copy: - src: docker-compose.yml - dest: "{{ (service_path, 'docker-compose.yml') | path_join }}" - mode: "0644" + - name: Import prepare tasks for common service + ansible.builtin.import_tasks: tasks/prepare-common-service.yml - name: Template the conditional-start script ansible.builtin.template: @@ -21,6 +18,37 @@ dest: "{{ (service_path, 'conditional-start.sh') | path_join }}" mode: "0755" + - name: Set webhook config path + ansible.builtin.set_fact: + config_path: "{{ (service_path, 'config') | path_join }}" + + - name: Create config directory + ansible.builtin.file: + path: "{{ config_path }}" + state: directory + mode: "0755" + + - name: Template main config + ansible.builtin.template: + src: yml.j2 + dest: "{{ (config_path, 'hooks.yml') | path_join }}" + mode: "0644" + register: cmd_result + + - name: Set the docker force-recreate flag + ansible.builtin.set_fact: + docker_force_recreate: --force-recreate + when: cmd_result.changed # noqa: no-handler We need to handle the restart per service. Handlers don't support variables. + + - name: Copy the teamspeak-fallback-db script + ansible.builtin.copy: + src: teamspeak-fallback-db + dest: "{{ (config_path, 'teamspeak-fallback-db') | path_join }}" + mode: "0755" + + - name: Import start tasks for common service + ansible.builtin.import_tasks: tasks/start-common-service.yml + - name: Copy the system service ansible.builtin.template: src: teamspeak-fallback.service.j2 diff --git a/roles/teamspeak_fallback/templates/conditional-start.sh.j2 b/roles/teamspeak_fallback/templates/conditional-start.sh.j2 index e06184a..156ae82 100644 --- a/roles/teamspeak_fallback/templates/conditional-start.sh.j2 +++ b/roles/teamspeak_fallback/templates/conditional-start.sh.j2 @@ -6,12 +6,12 @@ do then if docker compose ps --services | grep teamspeak >/dev/null; then echo "Stopping Server" - docker compose down + docker compose down teamspeak fi else if ! docker compose ps --services | grep teamspeak >/dev/null; then echo "Starting Server" - docker compose up -d --pull=always + docker compose up -d --pull=always teamspeak fi fi sleep 2 diff --git a/roles/teamspeak_fallback/vars/main.yml b/roles/teamspeak_fallback/vars/main.yml index 154cf00..3a30806 100644 --- a/roles/teamspeak_fallback/vars/main.yml +++ b/roles/teamspeak_fallback/vars/main.yml @@ -2,5 +2,62 @@ teamspeak_fallback_check_server: ts.sneiso.eu teamspeak_fallback_check_port: 30033 +teamspeak_fallback_webhook_token: "{{ vault_teamspeak_fallback.webhook_token }}" + +teamspeak_fallback_user: 9987 +teamspeak_fallback_group: 9987 + teamspeak_fallback_svc: name: teamspeak-fallback + domain: ts.serguzim.me + additional_domains: + - hook.serguzim.me + port: 9000 + +teamspeak_fallback_env: + TEAMSPEAK_USER: "{{ teamspeak_fallback_user }}" + TEAMSPEAK_GROUP: "{{ teamspeak_fallback_group }}" + +teamspeak_fallback_yml: + - id: teamspeak-fallback-db + trigger-rule-mismatch-http-response-code: 400 + execute-command: /config/teamspeak-fallback-db + pass-file-to-command: + - source: payload + name: data + envname: WEBHOOK_DATA + base64decode: true + trigger-rule: + and: + - match: + type: value + value: "{{ teamspeak_fallback_webhook_token }}" + parameter: + source: header + name: X-Webhook-Token + +teamspeak_fallback_compose: + watchtower: true + image: ghcr.io/thecatlady/webhook + volumes: + - ./config:/config:ro + - data:/mnt/teamspeak_fallback_data + file: + services: + app: + command: ["-verbose", "-hooks=/config/hooks.yml"] + teamspeak: + image: teamspeak + restart: always + ports: + - 9987:9987/udp + - 10011:10011 + - 30033:30033 + environment: + TS3SERVER_DB_PLUGIN: ts3db_sqlite3 + TS3SERVER_DB_SQLCREATEPATH: create_sqlite + TS3SERVER_LICENSE: accept + volumes: + - data:/var/ts3server/ + volumes: + data: diff --git a/roles/webhook/tasks/main.yml b/roles/webhook/tasks/main.yml deleted file mode 100644 index 5fa9415..0000000 --- a/roles/webhook/tasks/main.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- name: Set common facts - ansible.builtin.import_tasks: tasks/set-default-facts.yml - -- name: Deploy {{ svc.name }} - vars: - svc: "{{ webhook_svc }}" - compose: "{{ webhook_compose }}" - env: "{{ webhook_env }}" - yml: "{{ webhook_yml }}" - block: - - name: Import prepare tasks for common service - ansible.builtin.import_tasks: tasks/prepare-common-service.yml - - - name: Set webhook config path - ansible.builtin.set_fact: - config_path: "{{ (service_path, 'config') | path_join }}" - - - name: Create config directory - ansible.builtin.file: - path: "{{ config_path }}" - state: directory - mode: "0755" - - - name: Template main config - ansible.builtin.template: - src: yml.j2 - dest: "{{ (config_path, 'hooks.yml') | path_join }}" - mode: "0644" - register: cmd_result - - - name: Set the docker force-recreate flag - ansible.builtin.set_fact: - docker_force_recreate: --force-recreate - when: cmd_result.changed # noqa: no-handler We need to handle the restart per service. Handlers don't support variables. - - - name: Copy the teamspeak-fallback-db script - ansible.builtin.copy: - src: teamspeak-fallback-db - dest: "{{ (config_path, 'teamspeak-fallback-db') | path_join }}" - mode: "0755" - - - name: Import start tasks for common service - ansible.builtin.import_tasks: tasks/start-common-service.yml diff --git a/roles/webhook/vars/main.yml b/roles/webhook/vars/main.yml deleted file mode 100644 index 2ed6748..0000000 --- a/roles/webhook/vars/main.yml +++ /dev/null @@ -1,45 +0,0 @@ ---- -webhook_teamspeak_fallback_db_token: "{{ vault_webhook.teamspeak_fallback_db_token }}" -webhook_teamspeak_user: 9987 -webhook_teamspeak_group: 9987 - -webhook_svc: - name: webhook - domain: hook.serguzim.me - port: 9000 - -webhook_env: - TEAMSPEAK_USER: "{{ webhook_teamspeak_user }}" - TEAMSPEAK_GROUP: "{{ webhook_teamspeak_group }}" - -webhook_yml: - - id: teamspeak-fallback-db - trigger-rule-mismatch-http-response-code: 400 - execute-command: /config/teamspeak-fallback-db - pass-file-to-command: - - source: payload - name: data - envname: WEBHOOK_DATA - base64decode: true - trigger-rule: - and: - - match: - type: value - value: "{{ webhook_teamspeak_fallback_db_token }}" - parameter: - source: header - name: X-Webhook-Token - -webhook_compose: - watchtower: true - image: ghcr.io/thecatlady/webhook - volumes: - - ./config:/config:ro - - teamspeak_fallback_data:/mnt/teamspeak_fallback_data - file: - services: - app: - command: ["-verbose", "-hooks=/config/hooks.yml"] - volumes: - teamspeak_fallback_data: - name: teamspeak_fallback_data diff --git a/services.auto.tfvars b/services.auto.tfvars index 0166cb9..f3ab3fb 100644 --- a/services.auto.tfvars +++ b/services.auto.tfvars @@ -440,14 +440,25 @@ services = { "teamspeak_fallback" = { name = "teamspeak_fallback" host = "node003" - dns = [{ - domain = "serguzim.me" - target = "ts" - }] + dns = [ + { + domain = "serguzim.me" + target = "ts" + }, + { + domain = "serguzim.me" + target = "hook" + name = "teamspeak_fallback-hook" + alias = "teamspeak_fallback" + } + ] backup = [{ name = "teamspeak_fallback_data" type = "docker" }] + monitoring = { + group = "7-support" + } auth = false database = false s3 = false @@ -514,21 +525,6 @@ services = { s3 = false }, - "webhook" = { - name = "webhook" - host = "node003" - dns = [{ - domain = "serguzim.me" - target = "hook" - }] - monitoring = { - group = "7-support" - } - auth = false - database = false - s3 = false - }, - "wiki_js" = { name = "wiki_js" host = "node003"