verify-cluster.yml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 k3s kubectl is available
  11. stat:
  12. path: /usr/local/bin/k3s
  13. register: k3s_binary
  14. - name: Get cluster nodes status using k3s kubectl
  15. command: /usr/local/bin/k3s kubectl get nodes
  16. register: nodes_status
  17. environment:
  18. KUBECONFIG: /etc/rancher/k3s/k3s.yaml
  19. when: k3s_binary.stat.exists
  20. failed_when: false
  21. - name: Get cluster nodes status using direct kubectl
  22. command: kubectl get nodes
  23. register: nodes_status
  24. environment:
  25. KUBECONFIG: /etc/rancher/k3s/k3s.yaml
  26. when: not k3s_binary.stat.exists
  27. failed_when: false
  28. - name: Display cluster nodes status
  29. debug:
  30. msg: "{{ nodes_status.stdout_lines }}"
  31. when: nodes_status is succeeded
  32. - name: Get cluster info using k3s kubectl
  33. command: /usr/local/bin/k3s kubectl cluster-info
  34. register: cluster_info
  35. environment:
  36. KUBECONFIG: /etc/rancher/k3s/k3s.yaml
  37. when: k3s_binary.stat.exists
  38. failed_when: false
  39. - name: Get cluster info using direct kubectl
  40. command: kubectl cluster-info
  41. register: cluster_info
  42. environment:
  43. KUBECONFIG: /etc/rancher/k3s/k3s.yaml
  44. when: not k3s_binary.stat.exists
  45. failed_when: false
  46. - name: Display cluster info
  47. debug:
  48. msg: "{{ cluster_info.stdout_lines }}"
  49. when: cluster_info is succeeded
  50. - name: Display verification complete message
  51. debug:
  52. msg: "Cluster verification completed"