--- # Deploy kube-vip (control-plane HA VIP) via the k3s auto-deploy manifests dir. # k3s applies /server/manifests/*.yaml on start, so this is # reproducible and independent of Flux (see kube_vip_manifest_path in defaults/main.yml — # the dir follows k3s's --data-dir, which prod moves to /data/k3s). The same manifest is written on every # server so the DaemonSet survives the loss of any single node. # WHICH INTERFACE kube-vip ARPs THE VIP ON. Detected from this node's OWN k3s_node_ip # (inventory, per host) rather than a hardcoded subnet: the previous awk matched the # literal 192.168.1.5[0-2], i.e. DEV's node addresses, so on prod (192.168.2.10/.11/.12) # it returned nothing and the assert below aborted the play. k3s_node_ip is the same # address k3s advertises with --node-ip and is defined for dev and prod alike, so this # resolves eno1 on prod and the identical dev interface it always resolved before. # `ip addr show to /32` does the matching in iproute2 instead of a regex over dotted # quads (where `.` would match any character). - name: Detect the LAN interface holding this node's k3s_node_ip ansible.builtin.shell: >- set -o pipefail; ip -o -4 addr show to {{ k3s_node_ip }}/32 | awk '{print $2; exit}' args: executable: /bin/bash register: kube_vip_iface_detect changed_when: false - name: Resolve the kube-vip VIP interface (override wins, else detected) ansible.builtin.set_fact: kube_vip_vip_interface: >- {{ kube_vip_interface if (kube_vip_interface | length > 0) else (kube_vip_iface_detect.stdout | trim) }} - name: Fail early if no LAN interface could be resolved ansible.builtin.assert: that: - kube_vip_vip_interface is defined - kube_vip_vip_interface | length > 0 fail_msg: >- Could not detect the interface holding {{ k3s_node_ip }} for kube-vip on {{ inventory_hostname }} — set kube_vip_interface explicitly. - name: Ensure the k3s auto-deploy manifests directory exists ansible.builtin.file: path: "{{ kube_vip_manifest_path | dirname }}" state: directory owner: root group: root mode: "0700" - name: Template the kube-vip control-plane manifest (RBAC + DaemonSet) ansible.builtin.template: src: kube-vip.yaml.j2 dest: "{{ kube_vip_manifest_path }}" owner: root group: root mode: "0600"