--- - name: Install k3s on master node hosts: master become: yes vars: k3s_version: "v1.35.0+k3s1" k3s_download_url: "http://download.9981.tech/k3s-v1.35.0%2Bk3s1" master_ip: "47.113.186.215" k3s_token: "my-secret-token" tasks: - name: Stop and cleanup any existing k3s installation shell: | systemctl stop k3s 2>/dev/null || true pkill -f k3s 2>/dev/null || true rm -f /etc/systemd/system/k3s.service rm -rf /var/lib/rancher/k3s rm -rf /etc/rancher/k3s rm -rf /root/.kube register: cleanup_result ignore_errors: yes - name: Print cleanup status debug: msg: "Cleanup completed on master node" - name: Check if k3s binary exists stat: path: /usr/local/bin/k3s register: k3s_binary - name: Download k3s binary get_url: url: "{{ k3s_download_url }}" dest: /usr/local/bin/k3s mode: '0755' when: not k3s_binary.stat.exists - name: Print k3s binary status debug: msg: "k3s binary already exists, skipping download" when: k3s_binary.stat.exists - name: Create k3s systemd service file template: src: k3s.service.j2 dest: /etc/systemd/system/k3s.service mode: '0644' - name: Reload systemd daemon systemd: daemon_reload: yes - name: Enable and start k3s service systemd: name: k3s enabled: yes state: started - name: Wait for node-token file to be created wait_for: path: /var/lib/rancher/k3s/server/node-token timeout: 300 register: token_wait - name: Display success message debug: msg: "k3s master node installed and running successfully"