---
# This file processes each region to identify managed clusters
# It's included with a loop where current_region is the loop variable

- name: Get cluster names for the current region (debug)
  ansible.builtin.debug:
    var: vars[current_region]

- name: Get cluster names for the current region
  ansible.builtin.set_fact:
    current_region_clusters: "{{ vars[current_region].keys() | list }}"
  when: vars[current_region] is mapping

- name: Process each cluster in the region
  ansible.builtin.set_fact:
    managed_clusters: "{{ managed_clusters + [{'region': current_region, 'cluster': current_cluster}] }}"
  loop: "{{ current_region_clusters | default([]) }}"
  loop_control:
    loop_var: current_cluster
  when:
    - current_region_clusters is defined
    - vars[current_region][current_cluster] is mapping
    - vars[current_region][current_cluster]['is_hub'] is not defined or not vars[current_region][current_cluster]['is_hub']
