meta/ansible/roles/wetgit-app/tasks/main.yml
Coornhert d3536c74a4 chore(ansible): Meilisearch/Qdrant stack, web vhost, module-paden
- Meilisearch v1.12 + Qdrant v1.13 toegevoegd aan docker-compose
- Env vars voor MEILI_URL/QDRANT_URL/MISTRAL_API_KEY/FORGEJO_API_TOKEN
- Nieuwe web vhost (wetgit.nl) via wetgit-web.conf.j2
- Systemd service-paden:
  - wetgit.service → uvicorn wetgit.api.app:app
  - wetgit-celery.service → celery -A wetgit.tasks
- WETGIT_GIT_REPOS_DIR verplaatst naar {{ app_dir }}/app
  (data leeft op /opt/wetgit/app/rijk/)
- Nieuwe vault-secrets: meili_master_key, qdrant_api_key, mistral_api_key
2026-04-21 20:58:38 +02:00

137 lines
3.4 KiB
YAML

---
# WetGIT FastAPI application + Celery worker
# Deploys to /opt/wetgit/backend via rsync from local checkout.
#
# Directories are created by wetgit-forgejo role (runs first).
# This role syncs source code, installs deps, and manages systemd services.
# --- Code deployment via rsync ---
# NOTE: become: no is required on synchronize tasks because rsync
# runs locally and connects to the remote via SSH directly.
- name: Sync application code to server
ansible.posix.synchronize:
src: "{{ local_src_dir }}/src/"
dest: "{{ app_dir }}/backend/src/"
delete: yes
rsync_opts:
- "--exclude=__pycache__"
- "--exclude=*.pyc"
become: no
notify: restart wetgit
- name: Sync pyproject.toml
ansible.posix.synchronize:
src: "{{ local_src_dir }}/pyproject.toml"
dest: "{{ app_dir }}/backend/pyproject.toml"
become: no
notify: restart wetgit
- name: Check if local templates directory exists
stat:
path: "{{ local_src_dir }}/templates"
delegate_to: localhost
register: local_templates
become: no
- name: Sync web templates
ansible.posix.synchronize:
src: "{{ local_src_dir }}/templates/"
dest: "{{ app_dir }}/backend/templates/"
delete: yes
rsync_opts:
- "--exclude=__pycache__"
become: no
when: local_templates.stat.exists
notify: restart wetgit
- name: Check if local static directory exists
stat:
path: "{{ local_src_dir }}/static"
delegate_to: localhost
register: local_static
become: no
- name: Sync static assets
ansible.posix.synchronize:
src: "{{ local_src_dir }}/static/"
dest: "{{ app_dir }}/backend/static/"
delete: yes
become: no
when: local_static.stat.exists
- name: Set backend ownership
file:
path: "{{ app_dir }}/backend"
owner: www-data
group: www-data
recurse: yes
# --- Python venv and dependencies ---
- name: Create Python venv
command: python3 -m venv {{ app_dir }}/backend/venv
args:
creates: "{{ app_dir }}/backend/venv/bin/python"
- name: Install application with API dependencies
command: "{{ app_dir }}/backend/venv/bin/pip install --upgrade '.[api]'"
args:
chdir: "{{ app_dir }}/backend"
register: pip_install
changed_when: "'Successfully installed' in pip_install.stdout"
notify: restart wetgit
- name: Set venv ownership
file:
path: "{{ app_dir }}/backend/venv"
owner: www-data
group: www-data
recurse: yes
# --- Configuration ---
- name: Deploy environment file
template:
src: wetgit.env.j2
dest: "{{ app_dir }}/backend/.env"
owner: www-data
group: www-data
mode: "0600"
notify: restart wetgit
# --- Systemd services ---
- name: Deploy WetGIT systemd service
template:
src: wetgit.service.j2
dest: /etc/systemd/system/wetgit.service
owner: root
group: root
mode: "0644"
notify: restart wetgit
- name: Deploy Celery worker systemd service
template:
src: wetgit-celery.service.j2
dest: /etc/systemd/system/wetgit-celery.service
owner: root
group: root
mode: "0644"
notify: restart wetgit-celery
- name: Enable and start WetGIT service
systemd:
name: wetgit
enabled: yes
state: started
daemon_reload: yes
# Celery worker disabled — sync runs via cron, not Celery
# Enable when wetgit.pipeline has a proper Celery app
- name: Disable Celery worker (not yet configured)
systemd:
name: wetgit-celery
enabled: no
state: stopped
daemon_reload: yes