--- # - name: Setup Local Laptop Tools # hosts: localhost # connection: local # become: yes # tasks: # - name: Set ANSIBLE_CONFIG locally # become: yes # ansible.builtin.lineinfile: # path: "~/.bashrc" # line: 'export ANSIBLE_CONFIG="/mnt/f/Invixel/k8s-infra-cluster/ansible.cfg"' # state: present - name: Setup Laptop to Control K3s Cluster hosts: master become: yes vars: # Replace this with your Master's actual LAN or Tailscale IP master_public_ip: "192.168.3.91" local_kube_path: "~/.kube/config" tasks: - name: Ensure K3s is running with TLS SAN for the Public IP ansible.builtin.shell: | curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--tls-san {{ master_public_ip }}" sh - register: k3s_install - name: Wait for k3s.yaml to be fully generated ansible.builtin.wait_for: path: /etc/rancher/k3s/k3s.yaml search_regex: "certificate-authority-data" # Ensures the file isn't empty timeout: 30 # - name: Read k3s.yaml as plain text # ansible.builtin.command: cat /etc/rancher/k3s/k3s.yaml # register: k3s_config_raw # changed_when: false # - name: Prepare and save config to local laptop # delegate_to: localhost # become: no # ansible.builtin.copy: # # We use .stdout here because that's where the 'cat' text is stored # content: "{{ k3s_config_raw.stdout | replace('127.0.0.1', master_public_ip) }}" # dest: "{{ local_kube_path }}" # mode: '0600' - name: Read k3s.yaml from master ansible.builtin.slurp: src: /etc/rancher/k3s/k3s.yaml register: k3s_config_encoded - name: Prepare and save config to local laptop delegate_to: localhost become: no ansible.builtin.copy: content: "{{ k3s_config_encoded.content | b64decode | replace('127.0.0.1', master_public_ip) }}" dest: "{{ local_kube_path }}" mode: '0600' # ansible-playbook -i hosts.ini k3s-remote-control.yml