verify-cluster.yml 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ---
  2. - name: Verify k3s cluster status
  3. hosts: master
  4. become: yes
  5. tasks:
  6. - name: Wait for k3s server to be ready
  7. wait_for:
  8. path: /var/lib/rancher/k3s/server/manifests
  9. timeout: 300
  10. - name: Check if kubectl is available
  11. command: which kubectl
  12. register: kubectl_check
  13. changed_when: false
  14. - name: Get cluster nodes status
  15. command: kubectl get nodes
  16. register: nodes_status
  17. environment:
  18. KUBECONFIG: /etc/rancher/k3s/k3s.yaml
  19. when: kubectl_check.rc == 0
  20. failed_when: false
  21. - name: Display cluster nodes status
  22. debug:
  23. msg: "{{ nodes_status.stdout_lines }}"
  24. when: nodes_status is succeeded
  25. - name: Get cluster info
  26. command: kubectl cluster-info
  27. register: cluster_info
  28. environment:
  29. KUBECONFIG: /etc/rancher/k3s/k3s.yaml
  30. when: kubectl_check.rc == 0
  31. failed_when: false
  32. - name: Display cluster info
  33. debug:
  34. msg: "{{ cluster_info.stdout_lines }}"
  35. when: cluster_info is succeeded
  36. - name: Display verification complete message
  37. debug:
  38. msg: "Cluster verification completed"