--- - name: Copy K3s configuration from vm1 to localhost hosts: localhost connection: local become: true become_user: root vars_files: - vars.yaml tasks: - name: Ensure .kube directory exists ansible.builtin.file: path: /home/vagrant/.kube state: directory owner: vagrant group: vagrant mode: "0700" - name: Copy kubeconfig using scp directly ansible.builtin.command: > scp -i ~/.ssh/vm1_key -o StrictHostKeyChecking=no vagrant@{{ vm1_ip }}:/home/vagrant/.kube/config /home/vagrant/.kube/config become: false - name: Ensure proper ownership ansible.builtin.file: path: /home/vagrant/.kube/config owner: vagrant group: vagrant mode: "0600" become: false - name: copy k3s binary to /usr/local/bin/k3s ansible.builtin.command: > scp -i ~/.ssh/vm1_key -o StrictHostKeyChecking=no vagrant@{{ vm1_ip }}:/usr/local/bin/k3s /usr/local/bin/k3s become: true - name: symlink k3s to kubectl ansible.builtin.file: src: /usr/local/bin/k3s dest: /usr/local/bin/kubectl state: link become: true - name: Ensure KUBECONFIG is set in vagrant .bashrc ansible.builtin.lineinfile: path: /home/vagrant/.bashrc line: "export KUBECONFIG=~/.kube/config" state: present insertafter: EOF owner: vagrant group: vagrant mode: "0644" - name: Ensure kubectl completion is sourced in vagrant .bashrc ansible.builtin.lineinfile: path: /home/vagrant/.bashrc line: "source <(kubectl completion bash)" state: present insertafter: EOF owner: vagrant group: vagrant mode: "0644" - name: replace 127.0.0.1:6443 with {{ vm1_ip }}:6443 in .kube/config ansible.builtin.replace: path: /home/vagrant/.kube/config regexp: "127.0.0.1:6443" replace: "{{ k3s_url_ip }}:6443"