set dotenv-load

# Default: list available recipes
default:
    @just --list

# Install Ansible Galaxy collections
deps:
    ansible-galaxy collection install -r requirements.yml

# Set up the target host: install Docker and create the sovereign network
setup-host:
    ansible-playbook playbooks/site.yml --tags common

# Run molecule tests for all roles
test:
    #!/usr/bin/env bash
    set -euo pipefail
    roles=(authentik common forgejo graylog headscale jitsi matrix minio nextcloud roundcube stalwart vaultwarden wazuh website)
    failed=()
    for role in "${roles[@]}"; do
        echo "==> Testing role: $role"
        if ! (cd roles/$role && molecule test); then
            failed+=("$role")
        fi
    done
    if [ ${#failed[@]} -gt 0 ]; then
        echo "FAILED roles: ${failed[*]}"
        exit 1
    fi
    echo "All molecule tests passed."

# Run molecule tests for a single role: just test-role common
test-role role:
    cd roles/{{ role }} && molecule test

# Update an existing deployment (pull latest config, re-run all roles)
update:
    ansible-playbook playbooks/site.yml

# Update a single service: just update-service authentik
update-service service:
    ansible-playbook playbooks/site.yml --tags {{ service }}

# Dry-run the full deployment
check:
    ansible-playbook playbooks/site.yml --check --diff

# Lint the project
lint:
    ansible-lint
