From c7c9f6d5d16b15c74d3d91a61824b56dbcde0ef9 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 2 Nov 2026 22:35:03 +0000 Subject: [PATCH] netbird_client: manage the wt0 MTU in default.json --- netbird_client/defaults/netbird_client.yml | 2 ++ netbird_client/tasks/config.yml | 37 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/netbird_client/defaults/netbird_client.yml b/netbird_client/defaults/netbird_client.yml index 237e759..c135eaa 100644 --- a/netbird_client/defaults/netbird_client.yml +++ b/netbird_client/defaults/netbird_client.yml @@ -9,3 +9,5 @@ netbird_client: iface_blacklist_extra: [] # Overrides the --log-level of the netbird service when set log_level: + # MTU of wt0, written to /var/lib/netbird/default.json (netbird restarts on change); leave empty to keep the config as is + mtu: diff --git a/netbird_client/tasks/config.yml b/netbird_client/tasks/config.yml index 96c38fd..e0e25fc 100644 --- a/netbird_client/tasks/config.yml +++ b/netbird_client/tasks/config.yml @@ -36,6 +36,43 @@ cfg: "{{ netbird_config_stopped.content | b64decode | from_json }}" when: netbird_stopped is changed +- name: Read netbird config for the MTU + slurp: + src: /var/lib/netbird/default.json + register: netbird_config_mtu_file + when: netbird_client.mtu | default('') | string | length > 0 + tags: netbird_client_config + +- name: Set the wt0 MTU in the netbird config + when: netbird_config_mtu_file.content is defined + vars: + netbird_config_mtu: "{{ netbird_config_mtu_file.content | b64decode | from_json }}" + tags: netbird_client_config + block: + # netbird writes its in-memory config back on exit, so edit only while it is stopped + - name: Stop netbird to edit its MTU + systemd: + name: netbird + state: stopped + when: (netbird_config_mtu.MTU | default(0)) != (netbird_client.mtu | int) + notify: restart_netbird + register: netbird_mtu_stopped + + - name: Re-read netbird config after stop + slurp: + src: /var/lib/netbird/default.json + register: netbird_config_mtu_stopped + when: netbird_mtu_stopped is changed + + - name: Write MTU + copy: + dest: /var/lib/netbird/default.json + content: "{{ cfg | combine({'MTU': netbird_client.mtu | int}) | to_nice_json(indent=4, sort_keys=False) }}\n" + mode: "0600" + vars: + cfg: "{{ netbird_config_mtu_stopped.content | b64decode | from_json }}" + when: netbird_mtu_stopped is changed + - name: Set netbird log level copy: dest: /etc/systemd/system/netbird.service.d/20-log-level.conf