---
- name: 添加hosts
  hosts: all
  gather_facts: yes
  roles:
    - add_hosts

- name: 验证集群健康状态
  hosts: masters
  tasks:
    - name: 检查节点状态
      command: kubectl get nodes -o wide
      register: nodes_result
      become: yes

    - name: 检查所有节点Ready
      fail:
        msg: "有节点未就绪"
      when: "'NotReady' in nodes_result.stdout"

    - name: 检查核心组件
      command: kubectl get pods -n kube-system
      register: system_pods
      become: yes

    - name: 检查Calico网络
      command: kubectl get pods -n kube-system -l k8s-app=calico-node
      register: calico_pods
      become: yes

    - name: 显示验证结果
      debug:
        msg: |
          节点状态: ✅
          系统Pod: ✅  
          Calico网络: ✅
          内核升级和节点添加完成!

