From 02f19cbd390d5b0977f6156c7b5550d4a5fa7b5e Mon Sep 17 00:00:00 2001 From: Jonathan Agmon Date: Wed, 22 Apr 2026 09:05:36 +0300 Subject: [PATCH] add update-config --- ansible/playbooks/k3s-update-config.yml | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ansible/playbooks/k3s-update-config.yml diff --git a/ansible/playbooks/k3s-update-config.yml b/ansible/playbooks/k3s-update-config.yml new file mode 100644 index 0000000..b60832e --- /dev/null +++ b/ansible/playbooks/k3s-update-config.yml @@ -0,0 +1,42 @@ +--- +- name: Update k3s config and restart service on all nodes + hosts: k3s + become: true + serial: 1 + + pre_tasks: + - name: Detect network interface for ansible_host + ansible.builtin.shell: | + set -o pipefail + ip route get {{ ansible_host }} | grep -oP 'dev \K\w+' | head -1 + register: detected_iface + changed_when: false + failed_when: false + + - name: Set fact for node interface + ansible.builtin.set_fact: + k3s_node_iface: "{{ detected_iface.stdout | default('') }}" + when: detected_iface.rc == 0 and detected_iface.stdout | length > 0 + + tasks: + - name: Deploy k3s config.yaml + ansible.builtin.template: + src: templates/config.yaml + dest: /etc/rancher/k3s/config.yaml + owner: root + group: root + mode: "0600" + notify: Restart k3s + + handlers: + - name: Restart k3s + ansible.builtin.shell: | + sleep 2 && systemctl daemon-reload && systemctl restart k3s + async: 60 + poll: 0 + + - name: Wait for k3s to come back + ansible.builtin.wait_for_connection: + delay: 15 + timeout: 120 + listen: Restart k3s