feat: VictoriaMetrics и NetBird между панелью и ger-nod-02
ansible-core-net / deploy (push) Canceled after 0s
ansible-core-secrets / deploy (push) Canceled after 0s
ansible-ger-nod-02 / deploy (push) Canceled after 0s
ansible-opnsense / deploy (push) Canceled after 0s
ansible-core-mon / deploy (push) Successful in 58s
ansible-rus-central / deploy (push) Successful in 44s
ansible-core-net / deploy (push) Canceled after 0s
ansible-core-secrets / deploy (push) Canceled after 0s
ansible-ger-nod-02 / deploy (push) Canceled after 0s
ansible-opnsense / deploy (push) Canceled after 0s
ansible-core-mon / deploy (push) Successful in 58s
ansible-rus-central / deploy (push) Successful in 44s
Prometheus остаётся для LAN. Нода отдаёт метрики через vmagent, а панель ходит на неё по отдельному ключу NetBird, не через группу роутеров. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
5704272c18
commit
72a9c86e52
46 files changed
+13496
-25
No files matched your search
@@ -19,5 +19,8 @@ netbird_setup_key: "{{ lookup('env', 'NETBIRD_SETUP_KEY') }}"
|
||||
|
||||
netbird_router_group_name: "homelab-routers"
|
||||
netbird_setup_key_name: "homelab-routers-key"
|
||||
netbird_remnawave_group_name: "remnawave"
|
||||
netbird_remnawave_setup_key_name: "remnawave-peers"
|
||||
netbird_remnawave_setup_key: "{{ lookup('env', 'NETBIRD_REMNAWAVE_SETUP_KEY') }}"
|
||||
netbird_lan_network_id: "homelab-lan"
|
||||
netbird_lan_subnet: "192.168.1.0/24"
|
||||
@@ -228,6 +228,20 @@
|
||||
router_group_id=$(printf '%s' "${grp_resp}" | jq -r '.id')
|
||||
fi
|
||||
|
||||
remna_group_id=$(printf '%s' "${groups_json}" | jq -r --arg g "$NB_REMNAWAVE_GROUP" '.[] | select(.name == $g) | .id' | head -n 1)
|
||||
if [ -z "${remna_group_id}" ]; then
|
||||
grp_payload=$(jq -n --arg name "$NB_REMNAWAVE_GROUP" '{name: $name, peers: []}')
|
||||
grp_resp=$(curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/groups" \
|
||||
-H "Authorization: Token ${active_token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${grp_payload}")
|
||||
remna_group_id=$(printf '%s' "${grp_resp}" | jq -r '.id // empty')
|
||||
if [ -z "${remna_group_id}" ]; then
|
||||
echo "Не удалось создать группу NetBird для Remnawave" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
routes_json=$(curl "${CURL_OPTS[@]}" -H "Authorization: Token ${active_token}" "${API_BASE}/routes")
|
||||
existing_route_id=$(printf '%s' "${routes_json}" | jq -r --arg nid "$NB_LAN_NET_ID" --arg net "$NB_LAN_SUBNET" '.[] | select(.network_id == $nid or .network == $net) | .id' | head -n 1)
|
||||
|
||||
@@ -288,21 +302,57 @@
|
||||
setup_key_updated=1
|
||||
fi
|
||||
|
||||
active_remna_key="${NB_REMNAWAVE_SETUP_KEY:-}"
|
||||
remna_key_updated=0
|
||||
valid_remna_id=$(printf '%s' "${keys_json}" | jq -r --arg kname "$NB_REMNAWAVE_KEY_NAME" '.[] | select(.name == $kname and .valid == true and .revoked == false) | .id' | head -n 1)
|
||||
if [ -z "${active_remna_key}" ] || [ -z "${valid_remna_id}" ]; then
|
||||
fresh_keys=$(curl "${CURL_OPTS[@]}" -H "Authorization: Token ${active_token}" "${API_BASE}/setup-keys")
|
||||
for old_kid in $(printf '%s' "${fresh_keys}" | jq -r --arg kname "$NB_REMNAWAVE_KEY_NAME" '.[] | select(.name == $kname) | .id'); do
|
||||
curl "${CURL_OPTS[@]}" -X DELETE -H "Authorization: Token ${active_token}" "${API_BASE}/setup-keys/${old_kid}" >/dev/null || true
|
||||
done
|
||||
key_payload=$(jq -n \
|
||||
--arg name "$NB_REMNAWAVE_KEY_NAME" \
|
||||
--arg gid "$remna_group_id" \
|
||||
'{
|
||||
name: $name,
|
||||
type: "reusable",
|
||||
expires_in: 31536000,
|
||||
revoked: false,
|
||||
auto_groups: [$gid],
|
||||
usage_limit: 0,
|
||||
ephemeral: false
|
||||
}')
|
||||
key_resp=$(curl "${CURL_OPTS[@]}" -X POST "${API_BASE}/setup-keys" \
|
||||
-H "Authorization: Token ${active_token}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${key_payload}")
|
||||
active_remna_key=$(printf '%s' "${key_resp}" | jq -r '.key // empty')
|
||||
if [ -z "${active_remna_key}" ]; then
|
||||
echo "Не удалось создать ключ установки remnawave-peers" >&2
|
||||
exit 1
|
||||
fi
|
||||
remna_key_updated=1
|
||||
fi
|
||||
|
||||
jq -n \
|
||||
--arg api_token "${active_token}" \
|
||||
--arg setup_key "${active_setup_key}" \
|
||||
--arg remna_key "${active_remna_key}" \
|
||||
--argjson admin_created "${admin_created}" \
|
||||
--argjson token_updated "${token_updated}" \
|
||||
--argjson setup_key_updated "${setup_key_updated}" \
|
||||
--argjson remna_key_updated "${remna_key_updated}" \
|
||||
--argjson route_created "${route_created}" \
|
||||
'{
|
||||
api_token: $api_token,
|
||||
setup_key: $setup_key,
|
||||
remnawave_setup_key: $remna_key,
|
||||
admin_created: ($admin_created == 1),
|
||||
token_updated: ($token_updated == 1),
|
||||
setup_key_updated: ($setup_key_updated == 1),
|
||||
remnawave_setup_key_updated: ($remna_key_updated == 1),
|
||||
route_created: ($route_created == 1),
|
||||
changed: (($admin_created + $token_updated + $setup_key_updated + $route_created) > 0)
|
||||
changed: (($admin_created + $token_updated + $setup_key_updated + $remna_key_updated + $route_created) > 0)
|
||||
}'
|
||||
args:
|
||||
executable: /bin/bash
|
||||
@@ -314,6 +364,9 @@
|
||||
NB_SETUP_KEY: "{{ netbird_setup_key }}"
|
||||
NB_ROUTER_GROUP: "{{ netbird_router_group_name }}"
|
||||
NB_SETUP_KEY_NAME: "{{ netbird_setup_key_name }}"
|
||||
NB_REMNAWAVE_GROUP: "{{ netbird_remnawave_group_name }}"
|
||||
NB_REMNAWAVE_KEY_NAME: "{{ netbird_remnawave_setup_key_name }}"
|
||||
NB_REMNAWAVE_SETUP_KEY: "{{ netbird_remnawave_setup_key }}"
|
||||
NB_LAN_NET_ID: "{{ netbird_lan_network_id }}"
|
||||
NB_LAN_SUBNET: "{{ netbird_lan_subnet }}"
|
||||
register: netbird_bootstrap_raw
|
||||
@@ -331,6 +384,7 @@
|
||||
--path="/services/netbird" \
|
||||
"NETBIRD_API_TOKEN=${NEW_API_TOKEN}" \
|
||||
"NETBIRD_SETUP_KEY=${NEW_SETUP_KEY}" \
|
||||
"NETBIRD_REMNAWAVE_SETUP_KEY=${NEW_REMNAWAVE_SETUP_KEY}" \
|
||||
--silent
|
||||
args:
|
||||
executable: /bin/bash
|
||||
@@ -339,7 +393,11 @@
|
||||
environment:
|
||||
NEW_API_TOKEN: "{{ (netbird_bootstrap_raw.stdout | from_json).api_token }}"
|
||||
NEW_SETUP_KEY: "{{ (netbird_bootstrap_raw.stdout | from_json).setup_key }}"
|
||||
when: (netbird_bootstrap_raw.stdout | from_json).token_updated or (netbird_bootstrap_raw.stdout | from_json).setup_key_updated
|
||||
NEW_REMNAWAVE_SETUP_KEY: "{{ (netbird_bootstrap_raw.stdout | from_json).remnawave_setup_key }}"
|
||||
when: >-
|
||||
(netbird_bootstrap_raw.stdout | from_json).token_updated or
|
||||
(netbird_bootstrap_raw.stdout | from_json).setup_key_updated or
|
||||
(netbird_bootstrap_raw.stdout | from_json).remnawave_setup_key_updated
|
||||
changed_when: true
|
||||
no_log: true
|
||||
|
||||
@@ -352,4 +410,5 @@
|
||||
- "Суперпользователь создан в этом прогоне: {{ nb_state.admin_created }}"
|
||||
- "API-токен обновлен в Infisical: {{ nb_state.token_updated }}"
|
||||
- "Setup-ключ обновлен в Infisical: {{ nb_state.setup_key_updated }}"
|
||||
- "Ключ remnawave-peers обновлен в Infisical: {{ nb_state.remnawave_setup_key_updated }}"
|
||||
- "Маршрут {{ netbird_lan_subnet }} создан в этом прогоне: {{ nb_state.route_created }}"
|
||||
Reference in new issue
Block a user