--- - name: Check if k3s is installed ansible.builtin.stat: path: /usr/local/bin/k3s register: k3s_binary - name: Download k3s installer ansible.builtin.get_url: url: https://get.k3s.io dest: /tmp/k3s-install.sh mode: "0755" when: not k3s_binary.stat.exists - name: Install k3s server ansible.builtin.command: cmd: /tmp/k3s-install.sh environment: INSTALL_K3S_VERSION: "{{ k3s_version }}" K3S_TOKEN: "{{ k3s_token }}" INSTALL_K3S_EXEC: "server {{ k3s_server_args }}" when: not k3s_binary.stat.exists changed_when: true - name: Wait for k3s to be ready ansible.builtin.command: cmd: k3s kubectl get nodes register: k3s_ready retries: 30 delay: 10 until: k3s_ready.rc == 0 changed_when: false - name: Fetch kubeconfig ansible.builtin.fetch: src: /etc/rancher/k3s/k3s.yaml dest: "{{ playbook_dir }}/../../kubeconfig" flat: true run_once: true - name: Update kubeconfig server URL ansible.builtin.lineinfile: path: "{{ playbook_dir }}/../../kubeconfig" regexp: "server: https://127.0.0.1:6443" line: " server: https://{{ ansible_host }}:6443" delegate_to: localhost become: false run_once: true