---
- name: Label worker nodes
  ansible.builtin.command:
    cmd: 'kubectl label nodes {{ hostvars[item].ansible_hostname }} node-role.kubernetes.io/worker=worker --kubeconfig=/etc/kubernetes/admin.conf'
  delegate_to: "{{ groups['control_plane'][0] }}"
  loop: "{{ groups['worker_nodes'] }}"
  run_once: true

- name: Get Kubernetes cluster nodes
  ansible.builtin.shell:
    cmd: 'kubectl get nodes --kubeconfig=/etc/kubernetes/admin.conf'
  delegate_to: "{{ groups['control_plane'][0] }}"
  run_once: true
  register: kubectl_get_nodes_result

- name: Print the result of kubectl get nodes
  ansible.builtin.debug:
    msg: '{{ kubectl_get_nodes_result.stdout_lines }}'
