add update-config

This commit is contained in:
2026-04-22 09:05:36 +03:00
parent a6e24c1d01
commit 02f19cbd39

View File

@@ -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