---
- import_playbook: hook/pre_install.yaml

# Load default variables and perform prechecks on all hosts
- hosts:
    - all
  gather_facts: true
  roles:
    - defaults
    - precheck
    - native/root

# Download all required software and generate certificates on the localhost
- hosts:
    - localhost
  gather_facts: true
  roles:
    - certs/init
    - download

# Initialize all nodes and install necessary software packages
- hosts:
    - etcd
    - k8s_cluster
    - image_registry
    - nfs
  roles:
    - native

# Install the etcd cluster
- hosts:
    - etcd
  gather_facts: true
  roles:
    - etcd

- hosts:
    - k8s_cluster
  roles:
    - role: cri
      when: or (.add_nodes | default list | empty) (.add_nodes | default list | has .inventory_hostname)
    - role: kubernetes/init-kubernetes
      when: or (.add_nodes | default list | empty) (.add_nodes | default list | has .inventory_hostname)
    - role: kubernetes/pre-kubernetes
      when: or (.add_nodes | default list | empty) (.add_nodes | default list | has .inventory_hostname) 
    - role: kubernetes/join-kubernetes
      when: or (.add_nodes | default list | empty) (.add_nodes | default list | has .inventory_hostname)
    - role: kubernetes/certs
      when: 
        - or (.add_nodes | default list | empty) (.add_nodes | default list | has .inventory_hostname)
        - .groups.kube_control_plane | default list | has .inventory_hostname
        - .kubernetes.certs.renew  
