---
# k3scluster-post-deploy.yml — Configure k3scluster blueprint instances
#
# Aether sends ffsdn_instances (a list of all instances in the deployment).
# This playbook loops over each instance and dispatches to control or worker tasks.

- name: K3scluster post-deploy — configure instances via Incus API
  hosts: localhost
  gather_facts: false
  connection: local

  vars:
    incus_api: "https://192.168.102.140:8443"
    incus_cert: "/runner/project/incus-client.crt"
    incus_key: "/runner/project/incus-client.key"
    base_packages: "curl vim htop jq"
    blueprint_name: "k3scluster"
    valid_components: ["control", "worker"]

  tasks:
    - name: Validate required variables
      ansible.builtin.assert:
        that:
          - ffsdn_instances is defined
          - ffsdn_instances | length > 0
        fail_msg: "ffsdn_instances must be provided by Aether"

    - name: Configure each instance
      ansible.builtin.include_tasks: showcase/k3scluster-deploy-instance.yml
      loop: "{{ ffsdn_instances }}"
      loop_control:
        loop_var: instance
