43 lines
1.1 KiB
YAML
43 lines
1.1 KiB
YAML
---
|
|
- 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
|