---
# Demo setup for Veza V5 Ultra deployment
# Shows the deployment process without requiring sudo

- name: Demo Veza V5 Ultra deployment setup
  hosts: edge
  gather_facts: true
  become: false
  connection: local

  tasks:
    - name: Check system information
      debug:
        msg: |
          System: {{ ansible_distribution }} {{ ansible_distribution_version }}
          Architecture: {{ ansible_architecture }}
          Python: {{ ansible_python_version }}
          User: {{ ansible_user_id }}

    - name: Check if required packages are installed
      command: which {{ item }}
      register: package_check
      failed_when: false
      loop:
        - python3
        - curl
        - git
        - wget

    - name: Display package availability
      debug:
        msg: "{{ item.item }}: {{ 'Available' if item.rc == 0 else 'Not installed' }}"
      loop: "{{ package_check.results }}"

    - name: Check if Incus is available
      command: which incus
      register: incus_check
      failed_when: false

    - name: Display Incus status
      debug:
        msg: "Incus: {{ 'Available' if incus_check.rc == 0 else 'Not installed' }}"

    - name: Check if snapd is available
      command: which snap
      register: snap_check
      failed_when: false

    - name: Display snapd status
      debug:
        msg: "Snapd: {{ 'Available' if snap_check.rc == 0 else 'Not installed' }}"

    - name: Check network interfaces
      command: ip addr show
      register: network_info
      failed_when: false

    - name: Display network interfaces
      debug:
        var: network_info.stdout_lines

    - name: Check if ports are available
      wait_for:
        port: "{{ item }}"
        host: localhost
        timeout: 1
      register: port_check
      failed_when: false
      loop:
        - 80
        - 443
        - 8080
        - 8081
        - 8082

    - name: Display port availability
      debug:
        msg: "Port {{ item.item }}: {{ 'Available' if item.skipped else 'In use' }}"
      loop: "{{ port_check.results }}"

    - name: Show deployment summary
      debug:
        msg: |
          ========================================
          Veza V5 Ultra Deployment Demo
          ========================================
          
          This demo shows the deployment process for Veza V5 Ultra:
          
          1. Bootstrap host (install packages, configure firewall)
          2. Install Incus + OVN (container runtime and networking)
          3. Create containers (haproxy, backend, chat, stream, web)
          4. Configure HAProxy + ACME (SSL termination and routing)
          5. Deploy applications (Go, Rust, React)
          6. Run smoke tests (validate all services)
          
          Target host: {{ ansible_host }}
          Domain: {{ domain | default('veza.talas.fr') }}
          
          Next steps:
          - Ensure target host is reachable via SSH
          - Run full deployment with: ./deploy-veza.sh
          - Or run individual playbooks step by step
          
          ========================================
