---
- name: 从主节点获取join命令
  delegate_to: "{{ groups['masters'][0] }}"
  become: yes
  command: kubeadm token create --print-join-command
  register: join_command

- name: 执行加入集群命令
  command: "{{ join_command.stdout }}"
  become: yes
  async: 600
  poll: 10

- name: 等待节点就绪
  wait_for:
    path: /etc/kubernetes/kubelet.conf
    state: present
  become: yes

- name: 配置kubeconfig权限
  file:
    path: /etc/kubernetes/kubelet.conf
    owner: root
    group: root
    mode: '0644'
  become: yes

- name: 验证节点状态
  command: kubectl get nodes -o wide
  delegate_to: "{{ groups['masters'][0] }}"
  become: yes
  register: node_status

- name: 显示节点状态
  debug:
    msg: "{{ node_status.stdout }}"

