---
- name: Set the Hostname
  ansible.builtin.hostname:
    name: "{{ inventory_hostname }}"

- name: Fix cmdline.txt
  import_tasks: cmdline.yml

- name: system.yml
  import_tasks: system.yml

- name: k9s.yml
  import_tasks: k9s.yml

- name: Flush handlers to Reboot if Required
  meta: flush_handlers

- name: CRI-O Installation
  import_tasks: cri-o.yml

- name: K8S Installation
  import_tasks: k8s_install.yml

- name: Install Client Config
  import_tasks: k8s_kubeadm_client.yml

## At this point, k8s is there, but we need to determine if a cluster has been created. If it has, then
## the nodes will all have .kube/config under fdamstra, and be able to talk to the master, and ask if
## there is a node marked 'k8s1', which is the node we bootstrap. If there is, then we skip all the 
## bootstrapping. If not, we:
##   a) Run the bootstrap on that node.
##   b) Do not run anything else whatsoever.
#- name: Check for k8s1
#  become_user: fdamstra
#  shell: kubectl get nodes | grep -c 'k8s1' || true
#  register: k8s1_status
#  changed_when: false # Do not mark as 'changed'
#  tags: wip
#
#- name: Determine Whether Bootstrap is Needed/Desired
#  set_fact:
#    bootstrap_needed: "{{ True if ( k8s_newinstall==True and k8s1_status.stdout == '0' ) else False }}"
#  tags: wip
#
#- name: Bootstrapping
#  import_tasks: bootstrap.yml
#  when: bootstrap_needed == True and inventory_hostname == "k8s1"
#
#- name: Join the cluster
#  import_tasks: k8s_join.yml
#  when: inventory_hostname != "k8s1" and not bootstrap_needed
#
#- name: Post joining tasks
#  import_tasks: k8s_postjoin.yml
#  when: not bootstrap_needed

