Join a fresh host to NetBird idempotently with the keyring, the management URL and the interface blacklist from the vars, and edit the blacklist and log level of a joined one

This commit is contained in:
2026-10-23 20:54:30 +00:00
parent a64d082c0c
commit a4648e0ea7
6 changed files with 97 additions and 14 deletions
+28 -7
View File
@@ -1,16 +1,37 @@
- name: Read the netbird status
when: "netbird_client.join_network.setup_key | default('') | length > 0"
command: netbird status -d
register: netbird_status
changed_when: false
failed_when: false
check_mode: false
# Joined means connected to the management server of the vars; without a management_url any server counts.
- name: Join netbird-network
when: "netbird_client.join_network.setup_key is defined"
command: "netbird up --management-url {{ netbird_client.join_network.management_url }} --setup-key {{ netbird_client.join_network.setup_key }}"
failed_when: command.rc != 0
changed_when: "'Connected' in command.stdout"
register: command
when:
- "netbird_client.join_network.setup_key | default('') | length > 0"
- netbird_status.stdout is not search(netbird_joined_pattern, multiline=True)
vars:
netbird_management_url: "{{ netbird_client.join_network.management_url | default('') }}"
netbird_joined_pattern: "^Management: Connected{{ (' to ' ~ (netbird_management_url | regex_escape) ~ '$') if netbird_management_url != '' else '' }}"
netbird_blacklist_extra: "{{ netbird_client.iface_blacklist_extra | default([]) }}"
netbird_up_argv: >-
{{ ['netbird', 'up']
+ (['--management-url', netbird_management_url] if netbird_management_url != '' else [])
+ ['--setup-key', netbird_client.join_network.setup_key]
+ (['--extra-iface-blacklist', netbird_blacklist_extra | join(',')] if netbird_blacklist_extra | length > 0 else []) }}
command:
argv: "{{ netbird_up_argv }}"
no_log: true
changed_when: true
register: join
- name: Wait for netbird-interface to exist
wait_for:
path: "/sys/class/net/wt0"
state: present
when: command.changed
when: join is changed
- name: Gather facts to get changes
ansible.builtin.gather_facts:
when: command.changed
when: join is changed