| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- ---
- - name: Verify k3s cluster status
- hosts: master
- become: yes
- tasks:
- - name: Wait for k3s server to be ready
- wait_for:
- path: /var/lib/rancher/k3s/server/manifests
- timeout: 300
- - name: Check if k3s kubectl is available
- stat:
- path: /usr/local/bin/k3s
- register: k3s_binary
- - name: Get cluster nodes status using k3s kubectl
- command: /usr/local/bin/k3s kubectl get nodes
- register: nodes_status
- environment:
- KUBECONFIG: /etc/rancher/k3s/k3s.yaml
- when: k3s_binary.stat.exists
- failed_when: false
- - name: Get cluster nodes status using direct kubectl
- command: kubectl get nodes
- register: nodes_status
- environment:
- KUBECONFIG: /etc/rancher/k3s/k3s.yaml
- when: not k3s_binary.stat.exists
- failed_when: false
- - name: Display cluster nodes status
- debug:
- msg: "{{ nodes_status.stdout_lines }}"
- when: nodes_status is succeeded
- - name: Get cluster info using k3s kubectl
- command: /usr/local/bin/k3s kubectl cluster-info
- register: cluster_info
- environment:
- KUBECONFIG: /etc/rancher/k3s/k3s.yaml
- when: k3s_binary.stat.exists
- failed_when: false
- - name: Get cluster info using direct kubectl
- command: kubectl cluster-info
- register: cluster_info
- environment:
- KUBECONFIG: /etc/rancher/k3s/k3s.yaml
- when: not k3s_binary.stat.exists
- failed_when: false
- - name: Display cluster info
- debug:
- msg: "{{ cluster_info.stdout_lines }}"
- when: cluster_info is succeeded
- - name: Display verification complete message
- debug:
- msg: "Cluster verification completed"
|