Compare commits

...
162 Commits
Author SHA1 Message Date
karpenok c064d518d1 refactor(agent_vault): move Gitea service registration to core-secrets playbook
ansible-deploy / deploy (core-secrets, ) (push) Successful in 21s
ansible-lint / lint (push) Successful in 3s
ansible-deploy / plan (push) Successful in 2s
2026-11-17 16:18:23 +07:00
karpenok 195830da21 fix(agent_vault): use token header prefix for Gitea API
ansible-deploy / plan (push) Successful in 2s
ansible-deploy / deploy (push) Skipped
ansible-lint / lint (push) Successful in 3s
2026-11-17 16:12:21 +07:00
karpenok 07e98ce7aa feat(agent_vault): register Grafana and Gitea API services
ansible-deploy / plan (push) Successful in 2s
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (core-mon, ) (push) Successful in 31s
2026-11-17 16:10:06 +07:00
karpenok 53626e9271 fix(monitoring): split gateway availability and default route timelines
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (core-mon, ) (push) Successful in 22s
ansible-deploy / plan (push) Successful in 2s
2026-11-17 16:03:11 +07:00
karpenok 376006e809 feat(monitoring): add OPNsense CPU, disk, load, uptime metrics and alerts
ansible-deploy / deploy (core-mon, ) (push) Successful in 33s
ansible-deploy / plan (push) Successful in 2s
ansible-lint / lint (push) Successful in 3s
2026-11-17 16:00:19 +07:00
karpenok 28ae06834b feat(monitoring): add OPNsense multi-WAN exporter, alerts, and Grafana dashboard
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (core-mon, ) (push) Successful in 43s
ansible-deploy / plan (push) Successful in 1s
2026-11-17 15:53:22 +07:00
karpenok c7adefd95a feat(traefik,opnsense): expose opnsense.gunihome.ru LAN-only with TLS and update Agent Vault host
ansible-deploy / plan (push) Successful in 2s
ansible-deploy / deploy (opnsense, ) (push) Successful in 10s
ansible-lint / lint (push) Successful in 2s
ansible-deploy / deploy (core-net, ) (push) Successful in 21s
2026-11-17 15:36:46 +07:00
karpenok 8061dd7604 feat(agent_vault,opnsense): support basic auth and register OPNsense API
ansible-deploy / plan (push) Successful in 1s
ansible-deploy / deploy (opnsense, ) (push) Successful in 10s
ansible-lint / lint (push) Successful in 3s
2026-11-17 15:27:02 +07:00
karpenok 15beca7bf0 fix(remnawave): use username/id on Remnawave v3 user PATCH and DELETE
ansible-deploy / plan (push) Successful in 2s
ansible-deploy / deploy (core-net, ) (push) Successful in 18s
ansible-lint / lint (push) Successful in 2s
2026-11-15 23:33:28 +07:00
karpenok 6e10d9dcbb feat(remnawave): scope user sync and pruning to managed_tag IAC
ansible-deploy / plan (push) Successful in 1s
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (core-net, ) (push) Failing after 16s
ansible-deploy / deploy (opnsense, ) (push) Successful in 3s
2026-11-15 23:30:33 +07:00
karpenok aab0611aaf refactor(opnsense/xray): replace 310-line Jinja loop with sync_xray.py
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (opnsense, ) (push) Successful in 3s
ansible-deploy / plan (push) Successful in 1s
2026-11-15 23:07:41 +07:00
karpenok ae9beee5ca feat(remnawave,monitoring): full node/host cleanup on sync and dynamic alerts.yml.j2
ansible-lint / lint (push) Successful in 3s
ansible-deploy / deploy (core-mon, ) (push) Successful in 17s
ansible-deploy / deploy (core-net, ) (push) Successful in 20s
ansible-deploy / plan (push) Successful in 2s
2026-11-15 23:00:55 +07:00
karpenok b2524d1d1e refactor(monitoring): split tasks into tagged subtasks, update BOOTSTRAP.md and .gitignore
ansible-deploy / deploy (core-mon, ) (push) Successful in 17s
ansible-deploy / plan (push) Successful in 2s
ansible-lint / lint (push) Successful in 3s
2026-11-15 22:55:54 +07:00
karpenok 0f0d4ff7ad fix(ci): chmod go-w and pass inventory in ansible-lint.yml, untrack pycache
ansible-deploy / deploy (push) Skipped
ansible-lint / lint (push) Successful in 2s
ansible-deploy / plan (push) Successful in 2s
2026-11-15 22:46:27 +07:00
karpenok fd0dcab300 ci: unify into matrix ansible-deploy.yml, add ansible-lint.yml and exit_nodes group
ansible-deploy / plan (push) Successful in 1s
ansible-deploy / deploy (core-secrets, ) (push) Successful in 17s
ansible-lint / lint (push) Failing after 3s
ansible-deploy / deploy (core-net, ) (push) Successful in 52s
ansible-deploy / deploy (ger-nod-02, ) (push) Successful in 1m18s
ansible-deploy / deploy (opnsense, ) (push) Successful in 9s
ansible-deploy / deploy (core-mon, ) (push) Successful in 26s
ansible-deploy / deploy (rus-central, ) (push) Successful in 52s
2026-11-15 22:44:34 +07:00
karpenok 189e31e266 ci: stop triggering all machine workflows on global ci/hosts/site changes 2026-11-15 22:38:15 +07:00
karpenok 07e3366578 fix(ci): allow deleting migrated machine-specific roles in ansible-target.sh
ansible-core-net / deploy (push) Successful in 51s
ansible-core-secrets / deploy (push) Successful in 16s
ansible-opnsense / deploy (push) Successful in 9s
ansible-rus-central / deploy (push) Successful in 55s
ansible-core-mon / deploy (push) Successful in 26s
ansible-ger-nod-02 / deploy (push) Successful in 1m19s
2026-11-15 22:34:26 +07:00
karpenok 2fc6e39323 refactor(remnawave,exit-node): split bootstrap/sync and generalize ger-nod-02 roles
ansible-core-net / deploy (push) Successful in 1m50s
ansible-ger-nod-02 / deploy (push) Failing after 3s
ansible-opnsense / deploy (push) Successful in 9s
ansible-rus-central / deploy (push) Successful in 1m7s
ansible-core-mon / deploy (push) Successful in 28s
ansible-core-secrets / deploy (push) Successful in 18s
2026-11-15 22:31:04 +07:00
karpenok 83baec4bad fix(ger-nod-02): дожидаться Management Connected после рестарта netbird
ansible-ger-nod-02 / deploy (push) Successful in 25s
2026-11-15 12:03:08 +07:00
karpenok c90a78e160 fix(netbird): отключить IPv6/DNS-перехват на Exit Node и сузить маршрут LAN
ansible-rus-central / deploy (push) Successful in 58s
ansible-ger-nod-02 / deploy (push) Failing after 43s
2026-11-15 11:59:40 +07:00
karpenok 4884a61ad2 refactor(netbird): вынести клиентский доступ и ключи в декларативный access.yml
ansible-rus-central / deploy (push) Successful in 30s
2026-11-14 13:02:24 +07:00
karpenok 3178455672 feat(netbird): настроить ger-nod-02 как Exit Node для клиентов
ansible-ger-nod-02 / deploy (push) Successful in 21s
ansible-rus-central / deploy (push) Successful in 26s
2026-11-14 12:36:07 +07:00
karpenokandCursor 2eadd3aedc chore(core-git): убрать проверку AppArmor, она больше не нужна
На обновлённом netcore задачи раннера идут без ручного профиля unconfined.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-13 23:48:54 +07:00
karpenokandCursor 321c78fc27 fix(core-git): не терять образ раннера и не деплоить из-за пустого файла
ansible-rus-central / deploy (push) Successful in 54s
ansible-opnsense / deploy (push) Successful in 8s
ansible-core-mon / deploy (push) Successful in 26s
ansible-core-net / deploy (push) Successful in 58s
ansible-core-secrets / deploy (push) Successful in 18s
ansible-ger-nod-02 / deploy (push) Successful in 1m18s
Архив homelab-ansible хранится на диске CT, проверка раннера вынесена в отдельную кнопку, cAdvisor смотрит свой порт.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-13 23:09:05 +07:00
karpenokandCursor db92435117 fix: убрать деплой core-git и apply CT 904 с раннера
ansible-core-net / deploy (push) Successful in 1m0s
ansible-ger-nod-02 / deploy (push) Successful in 1m14s
ansible-opnsense / deploy (push) Successful in 8s
ansible-rus-central / deploy (push) Successful in 57s
ansible-core-mon / deploy (push) Successful in 28s
ansible-core-secrets / deploy (push) Successful in 18s
Раннер живёт на этой машине, job не может её пересобирать.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-13 22:51:36 +07:00
karpenokandCursor f1838991bd fix(core-git): keyctl + AppArmor note for DinD Actions
ansible-core-git / deploy (push) Failing after 3s
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-13 22:43:24 +07:00
karpenokandCursor c8dda38c4f ci: проверка runner после чистого DinD + load образов
ansible-core-net / deploy (push) Failing after 1s
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-13 22:35:53 +07:00
karpenokandCursor 00bc7ead09 ci: проверка runner после восстановления DinD volume
ansible-core-net / deploy (push) Failing after 1s
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-13 22:33:42 +07:00
karpenokandCursor f48d7966ba ci: проверить Actions runner на core-git после сброса DinD
ansible-core-net / deploy (push) Failing after 16s
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-13 22:27:58 +07:00
karpenokandCursor 634a46c118 chore(core-git): cutover адресов на 192.168.1.105 после миграции
ansible-core-net / deploy (push) Failing after 0s
Traefik backend, clone/state URL в workflows и BOOTSTRAP. CT 109
оставлен для rollback.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-13 22:25:52 +07:00
karpenokandCursor 8e217b8585 fix(core-git): секреты Infisical и compose без up до миграции
ansible-core-net / deploy (push) Successful in 1m0s
ansible-core-secrets / deploy (push) Successful in 16s
ansible-rus-central / deploy (push) Successful in 1m6s
ansible-core-git / deploy (push) Successful in 14s
ansible-core-mon / deploy (push) Successful in 23s
ansible-ger-nod-02 / deploy (push) Successful in 1m28s
ansible-opnsense / deploy (push) Successful in 6s
Подключает POSTGRES_USER/DB/PASSWORD, пишет compose при секретах,
поднимает стек только при наличии PG_VERSION. Terraform: import-core-git.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-13 22:13:44 +07:00
karpenokandCursor c507ed1fdb feat(core-git): каркас машины CT 904 под Gitea до миграции
ansible-core-git / deploy (push) Successful in 27s
ansible-core-mon / deploy (push) Successful in 24s
ansible-core-secrets / deploy (push) Successful in 18s
ansible-core-net / deploy (push) Successful in 54s
ansible-ger-nod-02 / deploy (push) Successful in 1m15s
ansible-opnsense / deploy (push) Successful in 6s
ansible-rus-central / deploy (push) Successful in 50s
Добавляет terraform/ansible/CI и scrape cAdvisor. Стек Gitea без
POSTGRES_PASSWORD в Infisical не поднимается — данные придут с CT 109.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-13 22:00:53 +07:00
karpenok 090a92174b docs(agents): запретить вывод секретов и требовать сообщать о компрометации
Агент работает через прокси, ключи подставляет прокси, поэтому значения
секретов агенту не нужны. Всё, что попало в вывод команды или тело ответа,
уже в контексте модели, то есть у провайдера.

Добавлены два раздела: что запрещено по умолчанию (печать секретов, поиск
эндпоинтов с креденшлами, выпуск токенов «для проверки») и как сообщать
об утечке — сразу, с именем ключа и местом, без повторения значения,
с предложением отозвать и ротировать.
2026-11-13 21:16:54 +07:00
karpenok 99215bf7b1 feat(agent-vault): регистрировать панель NetBird в Access Bundle
ansible-core-net / deploy (push) Successful in 3s
ansible-rus-central / deploy (push) Successful in 22s
Роль agent_vault_service научилась переопределять заголовок креденшла:
NetBird ждёт Authorization: Token <pat>, а не Bearer, поэтому добавлены
agent_vault_service_header_name и agent_vault_service_header_prefix.

NetBird регистрируется после сохранения токена в /services/netbird:
host central.gunihome.ru:443, путь /api, только GET — панель управляет
пирами и маршрутами, запись пока не открываем.
2026-11-13 21:04:23 +07:00
karpenok e6e3cb162a feat(agent-vault): регистрировать сервисы продуктов в Access Bundle из роли
ansible-core-net / deploy (push) Successful in 25s
Общая роль agent_vault_service ищет сервис по имени в бандле, создаёт при
отсутствии и обновляет креденшл при наличии, поэтому ротация токена на
каждом прогоне не ломает доступ агента.

Креденшл читается из Infisical через infisical secrets get --plain и не
проходит через переменные Ansible. Если API не принял PATCH, сервис
пересоздаётся.

Remnawave регистрирует панель после сохранения API-токена в
/services/remnawave: хост rw.gunihome.ru:443, путь /api, GET и POST.

На версии v0.167.7 сервисы создаются bundle-scoped маршрутом
POST /api/v1/agent-vault/access-bundles/<id>/services: описанного в
документации POST /api/v1/agent-vault/services там ещё нет.
2026-11-13 20:57:02 +07:00
karpenok 8e0c6d9024 test(opnsense): вернуть активную подписку Germ-02 после проверки переключения
ansible-opnsense / deploy (push) Successful in 10s
2026-11-12 22:22:27 +07:00
karpenok bfe1babc3d test(opnsense): временно переключить активную подписку на Germ-01 (проверка переключения)
ansible-opnsense / deploy (push) Successful in 10s
2026-11-12 22:21:19 +07:00
karpenok 8c1f155c74 fix(opnsense): не обращаться к регистрам validate/testconnect когда они пропущены
ansible-opnsense / deploy (push) Successful in 4s
2026-11-12 22:18:20 +07:00
karpenok 192d1414f2 fix(opnsense): сравнивать loglevel OptionField по выбранной опции в drift-проверке
ansible-opnsense / deploy (push) Failing after 4s
2026-11-12 22:14:57 +07:00
karpenok f0c2d2e5a5 fix(opnsense): спрашивать статус xray по активному инстансу, а не первому в config.xml
ansible-opnsense / deploy (push) Successful in 12s
2026-11-12 22:07:06 +07:00
karpenok 7aef3fe063 fix(opnsense): не падать на first по пустой последовательности при поиске uuid активной подписки
ansible-opnsense / deploy (push) Successful in 11s
2026-11-12 22:05:38 +07:00
karpenok 1d0ab4da61 fix(opnsense): update active status for Xray instances in instances.yml
ansible-opnsense / deploy (push) Failing after 5s
- Set 'Fin-01' instance to inactive
- Set 'Germ-02' instance to active
2026-11-12 21:59:01 +07:00
karpenok d8d029f5b9 docs(bootstrap): описать роль opnsense/xray и секреты /services/opnsense-xray 2026-11-12 21:37:48 +07:00
karpenok f8f927450b chore(ci): убрать временный seed-workflow после сидинга Xray-ссылок 2026-11-12 21:37:05 +07:00
karpenok 931d8d0970 fix(opnsense): использовать Item-эндпоинты API os-xray (searchItem/getItem/setItem/addItem/delItem/toggleItem)
ansible-opnsense / deploy (push) Successful in 10s
2026-11-12 21:34:58 +07:00
karpenok 21f106993f feat(opnsense): синхронизировать подписки Xray через API плагина os-xray
ansible-core-mon / deploy (push) Successful in 26s
ansible-core-net / deploy (push) Successful in 52s
ansible-core-secrets / deploy (push) Successful in 16s
ansible-ger-nod-02 / deploy (push) Successful in 1m21s
ansible-opnsense / deploy (push) Failing after 5s
ansible-rus-central / deploy (push) Successful in 51s
- роль opnsense/xray: instances.yml как источник правды, ссылки vless://
  из Infisical /services/opnsense-xray, конвертер в outbound_config,
  переключение активной подписки с validate/testconnect и откатом
- deploy-machine.sh: выгрузка /services/opnsense-xray для машины opnsense
- временный workflow xray-secrets-seed для первичного сидинга ссылок
2026-11-12 21:26:56 +07:00
karpenokandCursor 32194a55a1 fix(monitoring): оставить Steal-Yali рядом с именем хоста
ansible-core-mon / deploy (push) Successful in 18s
По подписи должно быть видно, что инбаунд — self-steal заглушка, а не отдельный узел.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 19:39:34 +07:00
karpenokandCursor 62156b46a7 fix(monitoring): склеить старое имя Yali с ger-nod-02
ansible-core-mon / deploy (push) Successful in 18s
История метрик ещё подписана Yali, из-за этого на дашборде две карточки. Запросы показывают одно имя, флаг Германии остаётся.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 19:38:17 +07:00
karpenokandCursor cf02dfb726 fix(monitoring): подписать прокси ger-nod-02 вместо Yali
ansible-core-mon / deploy (push) Successful in 21s
Метрика xray-checker берёт имя из подписки. На дашборде оно заменяется на имя хоста, флаг Германии остаётся.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 19:34:22 +07:00
karpenokandCursor bcbb2564f1 fix(remnawave): показывать ноду как ger-nod-02
ansible-core-net / deploy (push) Successful in 23s
Подпись хоста в подписке была Yali. Дашборд берёт её из метрик xray-checker, флаг Германии остаётся.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 19:32:15 +07:00
karpenokandCursor c2e5a4a6bd fix(monitoring): смотреть рестарты контейнеров по метке Compose
ansible-core-mon / deploy (push) Successful in 16s
У cAdvisor нет метки container, из-за неё правило не видело ни одного ряда.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 19:10:01 +07:00
karpenokandCursor 296c54f840 feat(monitoring): закрыть пробелы в алертах хостов и сервисов
ansible-core-mon / deploy (push) Successful in 17s
Пуш-хосты больше не пропадают молча, а диск, OOM, cAdvisor, Remnawave и xray-checker доходят до ntfy.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 19:07:58 +07:00
karpenokandCursor a2b0c37522 fix(monitoring): строить Cadvisor exporter по сервису Compose
ansible-core-mon / deploy (push) Successful in 19s
cAdvisor 0.60 не заполняет лейбл name, из-за этого панели ger-nod-02 и rus-central были пустыми.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 18:23:51 +07:00
karpenokandCursor d0ba64aded fix(monitoring): поднять cAdvisor, который понимает Docker API 1.44
ansible-rus-central / deploy (push) Successful in 17s
ansible-ger-nod-02 / deploy (push) Successful in 24s
На ger-nod-02 и rus-central демон отвергает клиент 1.41, поэтому в дашборде не было контейнеров.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 18:21:20 +07:00
karpenokandCursor 93958f93e2 fix(monitoring): убрать Node Exporter Full и собирать cAdvisor со всех Docker-хостов
ansible-core-secrets / deploy (push) Successful in 27s
ansible-rus-central / deploy (push) Successful in 59s
ansible-core-mon / deploy (push) Successful in 20s
Старый дашборд оставался в каталоге Grafana, потому что копирование его не удаляет. core-secrets и rus-central не попадали в Cadvisor exporter: экспортёра на них не было.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 18:13:20 +07:00
karpenokandCursor 57aa12b9c5 feat(monitoring): заменить Prometheus на vmalert
ansible-core-mon / deploy (push) Successful in 37s
ansible-core-net / deploy (push) Successful in 56s
ansible-core-secrets / deploy (push) Successful in 16s
ansible-rus-central / deploy (push) Successful in 39s
ansible-ger-nod-02 / deploy (push) Successful in 1m22s
ansible-opnsense / deploy (push) Successful in 6s
Алерты считаются по VictoriaMetrics и уходят в тот же Alertmanager, второй сбор метрик больше не нужен.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 17:54:25 +07:00
karpenokandCursor 28b8bcf708 fix(monitoring): направить дашборд cAdvisor в VictoriaMetrics
ansible-core-mon / deploy (push) Successful in 20s
Плейсхолдер импорта DS_PROMETHEUS при провижининге не подставляется, панели смотрели в пустой источник.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 17:42:45 +07:00
karpenokandCursor df6ecd711f fix(monitoring): починить YAML задачи копирования дашбордов
ansible-core-mon / deploy (push) Successful in 19s
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 17:40:38 +07:00
karpenokandCursor c905f42a10 fix(monitoring): перечитывать дашборды Grafana после обновления файлов
ansible-core-mon / deploy (push) Failing after 3s
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 17:40:06 +07:00
karpenokandCursor efd5f27f6d fix(monitoring): перевести дашборд Remnawave на метрики process
ansible-core-mon / deploy (push) Successful in 18s
Панель 3 больше не отдаёт remnawave_nodejs_*: CPU и частоту запросов убрали, память и event loop переименовали.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 17:38:28 +07:00
karpenokandCursor b69e1c8f93 fix(monitoring): проверять Xray по HTTP-статусу, а не по IP
ansible-core-mon / deploy (push) Successful in 31s
Профиль ноды блокирует api.ipify.org, поэтому метод ip всегда помечал рабочий прокси офлайн.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 17:32:48 +07:00
karpenokandCursor b6d6db9e2c fix(remnawave): не переводить ноду на NetBird, пока панель сама не в сети
ansible-core-net / deploy (push) Canceled after 17s
Иначе панель без /dev/net/tun потеряет ger-nod-02, хотя peer ноды уже есть.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 16:59:30 +07:00
karpenokandCursor 13870d6399 fix(core-net): не ломать Terraform из-за запрета на /dev/net/tun
ansible-core-net / deploy (push) Failing after 59s
ansible-ger-nod-02 / deploy (push) Successful in 25s
Токен Proxmox не может пробросить устройство. Остальной стек панели ставится до роли NetBird, а команда для root@pam описана в bootstrap.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 16:57:19 +07:00
karpenokandCursor 83fde054b4 feat(core-net): пробросить /dev/net/tun для клиента NetBird
Unprivileged LXC иначе не поднимает WireGuard. Устройство появляется после одного перезапуска CT 902.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 16:55:12 +07:00
karpenokandCursor 72a9c86e52 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-core-mon / deploy (push) Successful in 58s
ansible-opnsense / deploy (push) Canceled after 0s
ansible-rus-central / deploy (push) Successful in 44s
Prometheus остаётся для LAN. Нода отдаёт метрики через vmagent, а панель ходит на неё по отдельному ключу NetBird, не через группу роутеров.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 16:50:44 +07:00
karpenokandCursor 5704272c18 fix: роль host один раз и рабочие маршруты Nextcloud
ansible-core-mon / deploy (push) Successful in 20s
ansible-core-net / deploy (push) Successful in 20s
ansible-ger-nod-02 / deploy (push) Successful in 41s
ansible-rus-central / deploy (push) Successful in 38s
Полная сверка больше не готовит машину дважды, а Traefik видит entryPoints у cloud и opencloud. Каталог старых маршрутов помечен как отложенный долг.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 14:21:32 +07:00
karpenokandCursor a54a25ebb7 fix(monitoring): Prometheus читает новый конфиг, а не старый inode
ansible-core-mon / deploy (push) Successful in 13s
Файл в bind-mount не обновлялся после записи Ansible, поэтому ger-nod-02 не попадал в цели.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 13:00:15 +07:00
karpenokandCursor 408dfd09c3 feat(monitoring): цели Prometheus из inventory и хосты в Grafana через up
ansible-core-mon / deploy (push) Successful in 26s
ansible-opnsense / deploy (push) Successful in 5s
ansible-core-net / deploy (push) Successful in 43s
ansible-core-secrets / deploy (push) Successful in 15s
ansible-ger-nod-02 / deploy (push) Successful in 55s
ansible-rus-central / deploy (push) Successful in 59s
Список scrape строится из inventory, дашборд показывает все цели, не только с успешным node_exporter.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 12:50:23 +07:00
karpenokandCursor 4316f2c68e fix(remnawave): gunihome.ru мимо туннеля в шаблоне Except-RU
ansible-core-net / deploy (push) Successful in 21s
Нода режет эти адреса правилом geoip:ru, как старый Steal. Свои сервисы должны идти напрямую с клиента.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 00:01:16 +07:00
karpenokandCursor e5bebab5d2 feat(remnawave): шаблон Except-RU на хосте yali
ansible-core-net / deploy (push) Successful in 19s
Старое имя NL_YT_TG_ONLY не совпадало с правилами: это полный туннель, RU идёт напрямую. JSON в базовой подписке включён.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 23:55:11 +07:00
karpenokandCursor abca41fd35 fix(ger-nod-02): обычная страница практики вместо заглушки SelfSteal
ansible-ger-nod-02 / deploy (push) Successful in 33s
Пустая карточка «ничего не смотрите» слишком явно читалась как маскировка.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 23:46:20 +07:00
karpenokandCursor c99c4cd10c fix(remnawave): не создавать повторно конфиг подписки Homelab
ansible-core-net / deploy (push) Successful in 19s
Список API отдаёт config=null, POST ловил 400 «name already exists».

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 23:42:36 +07:00
karpenokandCursor 0699aa9476 fix(remnawave): логи bootstrap видны, ключи только в файле
ansible-core-net / deploy (push) Failing after 11s
no_log остаётся на чтении секретов, Infisical и .env.
stdout задачи — статус без токена и SECRET_KEY.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 23:41:37 +07:00
karpenokandCursor e4fc3fce69 fix(remnawave): пользователи из файла, ротация API-токена без логов
ansible-core-net / deploy (push) Failing after 14s
users.yml — источник правды (homelab — первый). Именованный токен
перевыпускается каждый прогон и пишется в Infisical; stdout/stderr
секретов в CI закрыты no_log и redact.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 23:39:18 +07:00
karpenokandCursor 928c04ce9d fix(ger-nod-02): NODE_PORT с обоих WAN-провайдеров панели
ansible-core-net / deploy (push) Canceled after 0s
ansible-ger-nod-02 / deploy (push) Successful in 1m12s
213.128.28.107 — провайдер 1 (МТС), 185.160.137.140 — провайдер 2.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 23:26:38 +07:00
karpenokandCursor 1733a9f977 fix(ger-nod-02): правильный egress панели для NODE_PORT
ansible-core-net / deploy (push) Canceled after 5s
ansible-ger-nod-02 / deploy (push) Successful in 1m3s
В UFW был 213.128.28.107 (МТС), реал egress core-net —
185.160.137.140; панель не достукивалась до 2222, Xray не
поднимал 443.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 23:24:57 +07:00
karpenokandCursor 0a56b935de fix(ger-nod-02): пароль как у central, HTTP-01 без ACME TXT, кавычки SECRET_KEY
ansible-core-secrets / deploy (push) Canceled after 0s
ansible-core-net / deploy (push) Canceled after 0s
ansible-ger-nod-02 / deploy (push) Successful in 4m1s
ansible-rus-central / deploy (push) Canceled after 0s
ansible-opnsense / deploy (push) Canceled after 0s
ansible-core-mon / deploy (push) Canceled after 24s
Падение было на :443 — SECRET_KEY без кавычек ломал ноду.
DNS-01 убран: LE через standalone HTTP-01, старые _acme-challenge чистим.
ansible_password только из /VPS; host в плейбуке как у rus-central.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 23:20:02 +07:00
karpenokandCursor 0f7fe4e352 fix(ger-nod-02): передавать SSH args через JSON @file
ansible-core-net / deploy (push) Successful in 36s
ansible-core-secrets / deploy (push) Successful in 13s
ansible-opnsense / deploy (push) Successful in 4s
ansible-core-mon / deploy (push) Successful in 25s
ansible-ger-nod-02 / deploy (push) Failing after 3m21s
ansible-rus-central / deploy (push) Successful in 1m6s
-e ansible_ssh_common_args=-o ... резало значение по пробелам,
ssh получал голый -o и падал с UNREACHABLE.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 23:09:33 +07:00
karpenokandCursor 385505b5f7 fix(ger-nod-02): читать PASS из /VPS, Cloudflare из /ci-cd
ansible-core-mon / deploy (push) Successful in 26s
ansible-core-net / deploy (push) Successful in 36s
ansible-core-secrets / deploy (push) Successful in 13s
ansible-ger-nod-02 / deploy (push) Failing after 2s
ansible-opnsense / deploy (push) Successful in 4s
ansible-rus-central / deploy (push) Successful in 1m6s
Реальные пути в Infisical: CLOUDFLARE_API в /ci-cd, PASS_GER_NOD_02
в /VPS — без пароля SSH был Permission denied.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 23:06:05 +07:00
karpenokandCursor 6aa2b26f47 fix(remnawave): healthcheck subscription через docker health
ansible-core-net / deploy (push) Successful in 12s
Корень / рвёт коннект без Traefik+shortUuid; официальный probe —
/internal/health внутри контейнера (State.Health.Status).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:58:35 +07:00
karpenokandCursor dd19301c33 fix(remnawave): не светить ключи в CI + заметка в BOOTSTRAP
ansible-core-net / deploy (push) Failing after 1m0s
no_log на bootstrap; stderr API редáctит privateKey/SECRET_KEY/токены;
в BOOTSTRAP — правило для новых установок.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:53:40 +07:00
karpenokandCursor a4a0655888 fix(remnawave): парсить keypairs[] из x25519 generate v3
ansible-core-net / deploy (push) Failing after 1m27s
API отдаёт массив пар, а не одиночные privateKey/publicKey.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:48:29 +07:00
karpenokandCursor 8872b8765e fix(remnawave): bootstrap на admin JWT, API-токен со scopes *
ansible-core-net / deploy (push) Failing after 11s
Не переключаемся на API-токен mid-bootstrap (из-за этого был 403
на /keygen/). Токен создаём с wildcard; если нельзя — явный assert.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:45:51 +07:00
karpenokandCursor 6a59391a6c fix(remnawave): X-Remnawave-Client-Type browser для admin JWT
ansible-core-net / deploy (push) Failing after 12s
Без заголовка v3 отвечает 403 на /tokens и остальной API;
секреты админа всегда пишем в /services/remnawave.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:40:24 +07:00
karpenokandCursor 25bf393cab fix(remnawave): не парсить JSON bootstrap при rc!=0
ansible-core-net / deploy (push) Failing after 10s
Иначе Ansible глотает stderr; fail-таска печатает ошибку API.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:37:25 +07:00
karpenokandCursor d2d3c704be fix(remnawave): показать stderr bootstrap в CI
ansible-core-net / deploy (push) Failing after 9s
Админ уже создан; нужно увидеть, на каком API v3 падает дальше.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:34:48 +07:00
karpenokandCursor 39d1f66663 fix(remnawave): убрать ${#arr} из bootstrap-шаблона
ansible-core-net / deploy (push) Failing after 11s
Иначе lookup(template) ломается на Jinja-комментарии.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:31:45 +07:00
karpenokandCursor 8f17cbbb62 fix(remnawave): упростить запись секретов в Infisical
ansible-core-net / deploy (push) Failing after 12s
Убрать условные массивы и комментарии с {#, из-за которых
Ansible ломал разбор shell-задачи.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:31:12 +07:00
karpenokandCursor d8fc365ee8 fix(remnawave): не ломать shell на ${#args[@]} в Jinja
ansible-core-net / deploy (push) Failing after 1s
Ansible воспринимает {# как начало комментария.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:30:08 +07:00
karpenokandCursor 58aba40bc0 fix(remnawave): admin password v3 + bootstrap под Remnawave 3.4 API
ansible-core-net / deploy (push) Failing after 1s
ansible-opnsense / deploy (push) Failing after 2s
ansible-rus-central / deploy (push) Failing after 2s
ansible-core-mon / deploy (push) Failing after 2s
ansible-core-secrets / deploy (push) Failing after 2s
ansible-ger-nod-02 / deploy (push) Failing after 1s
Генерируем REMNAWAVE_ADMIN_* (≥24) в /services/remnawave; токены
через name/expiresInDays/scopes; SECRET_KEY ноды из GET /api/keygen/.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:29:10 +07:00
karpenokandCursor 5e0c2553ca fix(remnawave): убрать ulimits nofile для LXC на core-net
ansible-core-net / deploy (push) Failing after 26s
На unprivileged LXC rlimit 1048576 блокирует старт контейнеров;
pull вынесен отдельно с ретраями.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:21:48 +07:00
karpenokandCursor f9fc058b1a fix(remnawave): ensure Infisical folder exists before writing secrets
ansible-core-net / deploy (push) Failing after 1m8s
Create /services/remnawave if missing and pass INFISICAL_* into delegated localhost tasks explicitly.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:18:52 +07:00
karpenokandCursor 8caaddc779 feat(remnawave): declarative panel on core-net and SelfSteal node on ger-nod-02
ansible-core-mon / deploy (push) Successful in 25s
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-rus-central / deploy (push) Canceled after 0s
ansible-core-net / deploy (push) Failing after 26s
Add Remnawave panel+subscription behind Traefik (rw/sub.gunihome.ru), API bootstrap into Infisical, and ger-nod-02 node with Cloudflare DNS-01 SelfSteal (yali.gunis.top). Leaves remna.gunihome.ru on Golova untouched.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 22:15:45 +07:00
karpenok a0ec829eee fix(monitoring): escape go templates with raw block in alertmanager-ntfy template
ansible-core-mon / deploy (push) Successful in 12s
2026-11-11 21:06:52 +07:00
karpenok 317b5d6207 feat(monitoring): integrate alertmanager-ntfy and fix host dropdown in node exporter dashboard
ansible-core-net / deploy (push) Successful in 24s
ansible-core-secrets / deploy (push) Successful in 13s
ansible-rus-central / deploy (push) Successful in 1m1s
ansible-core-mon / deploy (push) Failing after 21s
2026-11-11 20:54:55 +07:00
karpenok bf4144a767 docs & refactor: sync secrets docs and clean up env var lookups
ansible-core-mon / deploy (push) Successful in 22s
ansible-core-net / deploy (push) Successful in 24s
ansible-core-secrets / deploy (push) Successful in 15s
ansible-opnsense / deploy (push) Successful in 6s
ansible-rus-central / deploy (push) Successful in 40s
2026-11-11 18:26:51 +07:00
karpenok e443b0fd97 feat(ci): fallback netbird admin credentials to /USER/ADMIN
ansible-core-mon / deploy (push) Successful in 22s
ansible-core-net / deploy (push) Successful in 24s
ansible-core-secrets / deploy (push) Successful in 12s
ansible-opnsense / deploy (push) Successful in 4s
ansible-rus-central / deploy (push) Successful in 37s
2026-11-11 18:09:36 +07:00
karpenok f78d765bac chore(monitoring): remove one-off grafana session cleanup task
ansible-core-mon / deploy (push) Successful in 10s
2026-11-11 18:07:24 +07:00
karpenok 583dd98566 feat(monitoring): enable ntfy web login and purge stale grafana oauth sessions
ansible-core-mon / deploy (push) Successful in 11s
2026-11-11 18:00:49 +07:00
karpenok 18a6b1fbe4 fix(authentik): use bool filter for authentik_enabled conditional
ansible-core-net / deploy (push) Successful in 6s
2026-11-11 17:48:38 +07:00
karpenok c0a9d7f0c8 refactor(auth): remove Authentik SSO, restore basic auth and provision Node Exporter dashboard
ansible-core-mon / deploy (push) Successful in 25s
ansible-core-net / deploy (push) Failing after 25s
ansible-core-secrets / deploy (push) Successful in 12s
ansible-opnsense / deploy (push) Successful in 5s
ansible-rus-central / deploy (push) Successful in 37s
2026-11-11 17:45:21 +07:00
karpenok 94a143623b fix(auth): add email fallback scope for Grafana OAuth and set attribute paths
ansible-core-mon / deploy (push) Successful in 9s
ansible-core-net / deploy (push) Successful in 18s
2026-11-11 17:07:00 +07:00
karpenok 811d65526b feat(auth): integrate Grafana and Ntfy with Authentik SSO
ansible-core-mon / deploy (push) Successful in 24s
ansible-core-net / deploy (push) Successful in 39s
ansible-core-secrets / deploy (push) Successful in 12s
ansible-opnsense / deploy (push) Successful in 3s
ansible-rus-central / deploy (push) Successful in 36s
2026-11-11 16:52:38 +07:00
karpenok 3670bb6033 feat(monitoring): sync grafana admin password from infisical via stdin
ansible-core-mon / deploy (push) Successful in 7s
2026-11-11 16:20:19 +07:00
karpenok 0205a5502a fix(host): clean up legacy docker exporter on core-mon
ansible-core-net / deploy (push) Successful in 28s
ansible-core-secrets / deploy (push) Successful in 12s
ansible-rus-central / deploy (push) Successful in 37s
ansible-core-mon / deploy (push) Successful in 20s
2026-11-11 16:15:15 +07:00
karpenok 7b2f6790c4 feat(host): install and enable prometheus-node-exporter on all managed hosts
ansible-core-mon / deploy (push) Failing after 31s
ansible-core-net / deploy (push) Successful in 50s
ansible-core-secrets / deploy (push) Successful in 38s
ansible-rus-central / deploy (push) Successful in 59s
2026-11-11 16:12:05 +07:00
karpenok 065c47aee2 fix(monitoring): copy alerts.yml without jinja2 templating
ansible-core-mon / deploy (push) Successful in 1m8s
ansible-core-net / deploy (push) Successful in 18s
2026-11-11 16:08:38 +07:00
karpenok 2445df7146 ci(core-mon): trigger full bootstrap of core-mon container
ansible-core-mon / deploy (push) Failing after 1m13s
2026-11-11 16:06:08 +07:00
karpenok f26e0bfe57 feat(monitoring): add core-mon ansible playbook, roles, workflows, and traefik routes
ansible-core-secrets / deploy (push) Successful in 12s
ansible-core-mon / deploy (push) Failing after 7s
ansible-core-net / deploy (push) Successful in 26s
ansible-opnsense / deploy (push) Successful in 3s
ansible-rus-central / deploy (push) Successful in 44s
2026-11-11 16:00:53 +07:00
karpenok 9e9b8e9caf feat(terraform): add core-mon LXC container definition on netcore 2026-11-11 15:56:07 +07:00
karpenok 38fc67048a fix(opnsense): set timeout for netbird up action
ansible-opnsense / deploy (push) Successful in 12s
2026-11-11 14:53:32 +07:00
karpenok ca604926d1 feat(traefik): add TCP SNI passthrough for central.gunihome.ru
ansible-core-net / deploy (push) Successful in 17s
2026-11-11 14:51:47 +07:00
karpenok 514d758600 fix(opnsense): use custom HTTPS WebGUI port 4433 for OPNsense REST API
ansible-opnsense / deploy (push) Failing after 33s
2026-11-11 13:00:43 +07:00
karpenok 822ae43992 feat(opnsense): add declarative NetBird plugin role and CI workflow
ansible-opnsense / deploy (push) Failing after 33s
2026-11-11 12:57:44 +07:00
karpenok 11b6539a7b fix(netbird): extract plain_token from PAT response and add OAuth2 PKCE token fallback
ansible-rus-central / deploy (push) Successful in 20s
2026-11-11 12:56:27 +07:00
karpenok 324327ee24 feat(netbird): automate admin setup, API token, setup key, and LAN route on rus-central
ansible-core-net / deploy (push) Successful in 25s
ansible-rus-central / deploy (push) Failing after 1m24s
ansible-core-secrets / deploy (push) Successful in 10s
2026-11-11 12:46:01 +07:00
karpenok 842a633916 chore(ansible,ci): align workflow paths, shared letsencrypt_email, and netbird task tags
ansible-core-secrets / deploy (push) Successful in 12s
ansible-core-net / deploy (push) Successful in 27s
ansible-rus-central / deploy (push) Successful in 36s
2026-11-11 11:35:45 +07:00
karpenokandCursor a0507719b0 refactor: drop the finished secrets migration from the deploy path
Product tags now come from the role directory, and edits to the CI scripts no longer redeploy every machine.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-11 00:09:23 +07:00
karpenokandCursor 9f337445a9 fix(authentik): pin Redis 8 so the existing RDB dump loads
ansible-core-net / deploy (push) Successful in 13s
Redis 7.4 refuses the dump written by the previous redis:alpine image, so Authentik stays down after deploy.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 23:59:31 +07:00
karpenokandCursor 9c692522fb refactor: split machine deploys from one-time secrets migration
ansible-core-net / deploy (push) Failing after 39s
ansible-rus-central / deploy (push) Failing after 15s
ansible-core-secrets / deploy (push) Successful in 30s
Roles stay under the machine that runs them, CI applies only a known product, and the /opt/secrets move is a one-shot playbook instead of part of every core-secrets run.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 23:55:34 +07:00
karpenok 341538fba9 refactor: update authentik configuration and convert core_net dashboard template to static file
ansible-core-net / deploy (push) Successful in 25s
2026-11-10 23:10:50 +07:00
karpenokandCursor a243ae281c fix(authentik): grant the embedded outpost access to its providers
ansible-core-net / deploy (push) Successful in 41s
The outpost service account could not see the Traefik provider, so the forward-auth path stayed on Django and returned Not Found.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 21:58:31 +07:00
karpenokandCursor 9e0dfa74c1 fix(traefik): send dashboard outpost paths to Authentik
ansible-core-net / deploy (push) Successful in 32s
The dashboard host was forwarding /outpost.goauthentik.io through forward auth, so Authentik answered with its own Not Found page.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 21:54:37 +07:00
karpenok 340964523e feat(authentik): integrate Traefik dashboard with Authentik for admin access control and streamline secret management
ansible-core-net / deploy (push) Successful in 33s
2026-11-10 21:27:56 +07:00
karpenok 3a8ef2579b feat(authentik): add blueprint directory setup and apply functionality
ansible-core-net / deploy (push) Successful in 35s
2026-11-10 21:03:25 +07:00
karpenok f0f3b61407 fix(authentik): use standard CMD redis-cli ping healthcheck
ansible-core-net / deploy (push) Successful in 30s
2026-11-10 20:03:40 +07:00
karpenok f7505333db fix(authentik): recursively enforce correct UIDs for postgres and redis data dirs
ansible-core-net / deploy (push) Failing after 30s
2026-11-10 19:56:20 +07:00
karpenok 172614e421 fix(authentik): set proper ownership and permissions for media and custom-templates dirs
ansible-core-net / deploy (push) Successful in 21s
2026-11-10 19:50:40 +07:00
karpenok 10cf792e4e feat(auth): deploy Authentik on CT 902 with Zero-Knowledge secret bootstrap and safe Traefik route
ansible-core-net / deploy (push) Successful in 2m39s
2026-11-10 19:40:54 +07:00
karpenok aad9733753 chore(infra): sync CT 902 disk size to 20G in terraform 2026-11-10 19:15:45 +07:00
karpenok 73d5172fc4 chore(infra): revert disk size in terraform to avoid container replacement 2026-11-10 19:11:00 +07:00
karpenok 28a89b2f26 chore(infra): increase CT 902 resources to 4GB RAM and 20GB disk for Authentik 2026-11-10 19:08:49 +07:00
karpenok 03b6b0ee56 fix(ci): decouple terraform state from traefik via direct gitea http and document master keys in bootstrap 2026-11-10 18:23:38 +07:00
karpenok f76cad9c73 fix(ci): decouple runner from traefik via direct infisical lan endpoint and pin traefik version
ansible-core-net / deploy (push) Successful in 31s
2026-11-10 17:54:39 +07:00
karpenok abe9280a30 fix(security): eliminate all plaintext hashes from CI and unify compose package in host role 2026-11-10 17:19:20 +07:00
karpenok 7b38efbd0e fix(ci): export both /ci-cd and /services/traefik in ansible-core-net 2026-11-10 17:05:12 +07:00
karpenok 2e5cd90781 fix(ci): store traefik secrets under /services/traefik in Infisical 2026-11-10 17:00:24 +07:00
karpenok 75b12de642 fix(ci): ensure /services/netbird folder is created in Infisical before setting secrets 2026-11-10 16:51:46 +07:00
karpenok 4ab29058fe fix(security): move dashboard auth and netbird secrets to Infisical lifecycle
ansible-core-net / deploy (push) Successful in 21s
2026-11-10 16:44:23 +07:00
karpenok 309b6538d0 fix(ansible): restore package name docker-compose for Debian 12
ansible-core-net / deploy (push) Successful in 18s
ansible-core-secrets / deploy (push) Successful in 16s
2026-11-10 15:18:47 +07:00
karpenok 5431e50d1c fix(security): remove root password, pin image versions, update compose package
ansible-core-net / deploy (push) Failing after 5s
ansible-core-secrets / deploy (push) Failing after 4s
2026-11-10 15:10:58 +07:00
karpenok 3a3b6914db remove obsolete pve-proxmox.yml dynamic inventory file
ansible-core-net / deploy (push) Successful in 19s
2026-11-10 13:05:31 +07:00
karpenok d8b56cc1a8 fix(ci): pass auth token explicitly to infisical export from universal-auth login 2026-11-10 12:04:55 +07:00
karpenok d2888c1149 feat(secrets): integrate Infisical Universal Auth into Gitea Actions workflows
ansible-core-net / deploy (push) Failing after 4m59s
ansible-core-secrets / deploy (push) Failing after 1m50s
- Configure Infisical CLI authentication via INFISICAL_CLIENT_ID and INFISICAL_CLIENT_SECRET
- Fetch runner SSH keys and state tokens dynamically from /ci-cd
- Fetch Proxmox target endpoints and tokens dynamically from /proxmox/<TARGET>
- Remove plaintext secrets from Ansible core_secrets defaults
- Clean up obsolete files and add --remove-orphans to docker compose invocations
2026-11-10 11:58:44 +07:00
karpenok efc23dfac2 feat(routes): switch pass.gunihome.ru to core-secrets (192.168.1.102)
ansible-core-net / deploy (push) Successful in 20s
2026-11-09 23:24:06 +07:00
karpenok e8344bb29a fix(ansible): ensure Docker is installed in core_net and fix package name in core_secrets
ansible-core-net / deploy (push) Successful in 20s
ansible-core-secrets / deploy (push) Successful in 2m41s
2026-11-09 22:49:49 +07:00
karpenok 4123a7689a feat(core-secrets): add Ansible role, compose stack, and CI/CD workflow
ansible-core-net / deploy (push) Successful in 16s
ansible-core-secrets / deploy (push) Failing after 12s
2026-11-09 22:34:27 +07:00
karpenok 3cefc59aee feat(terraform): declare CT 901 core-secrets on netcore 2026-11-09 22:08:48 +07:00
karpenok 3f306a0891 test: delete temporary probe_check.yml to verify runner deletion
ansible-core-net / deploy (push) Successful in 15s
2026-11-09 21:40:05 +07:00
karpenok 0cbb291fb6 test: add temporary probe_check.yml to verify runner addition
ansible-core-net / deploy (push) Successful in 16s
2026-11-09 21:38:56 +07:00
karpenok 2ded3a8585 feat(ci): enable automatic push trigger and declarative file deletion sync in core_net role
ansible-core-net / deploy (push) Successful in 16s
2026-11-09 21:35:29 +07:00
karpenok 93c3afaebf feat(ci): add ansible-core-net workflow to deploy Traefik to /opt/traefik via Gitea runner 2026-11-09 21:22:58 +07:00
karpenok 2ca68a26bb chore(ansible): specify root_home ssh key for core-net host 2026-11-09 21:06:13 +07:00
karpenok ed18326c6c feat(ansible): add core_net role, dynamic routes and playbook for Traefik gateway 2026-11-09 20:59:13 +07:00
karpenok 155a0b59cd fix(terraform): remove keyctl from core-net LXC (only nesting allowed by API token) 2026-11-09 20:49:30 +07:00
karpenok cd677eaadf revert: drop accidentally committed WIP files (keep only CI fix) 2026-11-09 20:31:32 +07:00
karpenok f4d6e537cc fix(ci): pass scoped TF_STATE_TOKEN to terraform http backend (GITEA_* secret names are reserved) 2026-11-09 20:31:17 +07:00
karpenok afd7661ee8 fix(ci): use /api/packages registry path for terraform state and per-target proxmox token 2026-11-09 20:30:14 +07:00
karpenok 2bc77b50f4 refactor(terraform): structure directories by hypervisor (netcore/ and pve/) 2026-11-09 20:11:28 +07:00
karpenok 2b23809bc3 feat(terraform): define core-net LXC container (CT 902) on netcore 2026-11-09 20:00:34 +07:00
karpenok 8e6f5dd5fe chore: update production inventory and remove terraform readme 2026-11-08 21:08:14 +07:00
karpenok 2ca6e9a402 docs: remove README.md 2026-11-08 18:42:58 +07:00
197 changed files with 22238 additions and 425 deletions

No files matched your search

+19
View File
@@ -1,7 +1,13 @@
FROM hashicorp/terraform:1.9.8 AS terraform
FROM infisical/cli:latest AS infisical
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
COPY --from=terraform /bin/terraform /usr/local/bin/terraform
COPY --from=infisical /bin/infisical /usr/local/bin/infisical
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
openssh-client \
@@ -10,6 +16,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
sshpass \
ca-certificates \
curl \
jq \
&& ansible-galaxy collection install ansible.posix community.general \
&& rm -rf /var/lib/apt/lists/*
# Настройка зеркала Terraform (обход гео-блокировки registry.terraform.io)
RUN cat <<'EOF' > /root/.terraformrc
provider_installation {
network_mirror {
url = "https://terraform-mirror.yandexcloud.net/"
include = ["registry.terraform.io/*/*"]
}
direct {
exclude = ["registry.terraform.io/*/*"]
}
}
EOF
View File
Whitespace-only changes.
+86
View File
@@ -0,0 +1,86 @@
name: ansible-deploy
on:
push:
branches:
- main
paths:
- 'ansible/**'
paths-ignore:
- 'ansible/ci/**'
workflow_dispatch:
inputs:
machine:
description: 'Целевая машина (или all для полного прогона)'
required: true
default: 'all'
type: choice
options:
- all
- core-net
- core-secrets
- core-mon
- rus-central
- ger-nod-02
- opnsense
tags:
description: 'Необязательный фильтр тегов (например: remnawave, netbird, monitoring)'
required: false
default: ''
type: string
jobs:
plan:
runs-on: homelab
container:
image: homelab-ansible:latest
outputs:
matrix: ${{ steps.calc.outputs.matrix }}
has_targets: ${{ steps.calc.outputs.has_targets }}
steps:
- name: Вычислить затронутые машины
id: calc
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_BEFORE: ${{ github.event.before }}
EVENT_SHA: ${{ github.sha }}
INPUT_MACHINE: ${{ inputs.machine || 'all' }}
INPUT_TAGS: ${{ inputs.tags || '' }}
run: |
set -eu
rm -rf "${HOME}/homelab-infra"
git clone http://192.168.1.105:3000/karpenok/homelab-infra.git "${HOME}/homelab-infra"
sha="${GITHUB_SHA:-${GITEA_SHA:-}}"
if [ -n "${sha}" ]; then
git -C "${HOME}/homelab-infra" checkout "${sha}"
fi
python3 "${HOME}/homelab-infra/ansible/ci/ansible-plan.py"
deploy:
needs: plan
if: needs.plan.outputs.has_targets == 'true'
runs-on: homelab
container:
image: homelab-ansible:latest
timeout-minutes: 45
strategy:
fail-fast: false
max-parallel: 1
matrix: ${{ fromJSON(needs.plan.outputs.matrix) }}
steps:
- name: Деплой ${{ matrix.machine }}
env:
INFISICAL_CLIENT_ID: ${{ secrets.INFISICAL_CLIENT_ID }}
INFISICAL_CLIENT_SECRET: ${{ secrets.INFISICAL_CLIENT_SECRET }}
run: |
set -eu
rm -rf "${HOME}/homelab-infra"
git clone http://192.168.1.105:3000/karpenok/homelab-infra.git "${HOME}/homelab-infra"
sha="${GITHUB_SHA:-${GITEA_SHA:-}}"
if [ -n "${sha}" ]; then
git -C "${HOME}/homelab-infra" checkout "${sha}"
fi
chmod -R go-w "${HOME}/homelab-infra"
exec bash "${HOME}/homelab-infra/ansible/ci/deploy-machine.sh" \
"${{ matrix.machine }}" "${{ github.event_name }}" "${{ github.event.before }}" "${{ github.sha }}" "${{ matrix.tags }}"
+37
View File
@@ -0,0 +1,37 @@
name: ansible-lint
on:
push:
branches:
- main
paths:
- 'ansible/**'
jobs:
lint:
runs-on: homelab
container:
image: homelab-ansible:latest
timeout-minutes: 10
steps:
- name: Проверка синтаксиса скриптов, Python и плейбуков
run: |
set -eu
rm -rf "${HOME}/homelab-infra"
git clone http://192.168.1.105:3000/karpenok/homelab-infra.git "${HOME}/homelab-infra"
sha="${GITHUB_SHA:-${GITEA_SHA:-}}"
if [ -n "${sha}" ]; then
git -C "${HOME}/homelab-infra" checkout "${sha}"
fi
chmod -R go-w "${HOME}/homelab-infra"
cd "${HOME}/homelab-infra"
sh -n ansible/ci/ansible-target.sh
bash -n ansible/ci/deploy-machine.sh
python3 -m py_compile ansible/ci/ansible-plan.py \
ansible/roles/core-net/remnawave/files/sync_remnawave.py \
ansible/roles/rus-central/netbird/files/sync_access.py \
ansible/roles/opnsense/xray/files/vless_to_outbound.py \
ansible/roles/opnsense/xray/files/sync_xray.py
cd ansible
ansible-playbook --syntax-check -i inventories/prod/hosts.yml playbooks/*.yml
-54
View File
@@ -1,54 +0,0 @@
name: netbird-install
on:
workflow_dispatch:
inputs:
letsencrypt_email:
description: Почта для уведомлений Let's Encrypt (по умолчанию из group_vars/all.yml)
required: false
type: string
default: 'vvkarpenok@gmail.com'
jobs:
install:
runs-on: homelab
container:
image: homelab-ansible:latest
timeout-minutes: 30
steps:
- name: Запустить плейбук NetBird
env:
RUNNER_SSH_KEY: ${{ secrets.RUNNER_SSH_KEY }}
NETBIRD_LETSENCRYPT_EMAIL: ${{ inputs.letsencrypt_email }}
run: |
set -eu
if [ -z "${RUNNER_SSH_KEY}" ]; then
echo "В секретах нет RUNNER_SSH_KEY." >&2
exit 1
fi
rm -rf "${HOME}/homelab-infra"
git clone https://gitea.gunihome.ru/karpenok/homelab-infra.git "${HOME}/homelab-infra"
sha="${GITHUB_SHA:-${GITEA_SHA:-}}"
if [ -n "${sha}" ]; then
git -C "${HOME}/homelab-infra" checkout "${sha}"
fi
chmod -R go-w "${HOME}/homelab-infra"
install -d -m 700 "${HOME}/.ssh"
printf '%s\n' "${RUNNER_SSH_KEY}" > "${HOME}/.ssh/id_ed25519"
chmod 600 "${HOME}/.ssh/id_ed25519"
trap 'rm -f "${HOME}/.ssh/id_ed25519"' EXIT
cd "${HOME}/homelab-infra/ansible"
extra_args=()
if [ -n "${NETBIRD_LETSENCRYPT_EMAIL:-}" ]; then
extra_args+=("-e" "netbird_letsencrypt_email=${NETBIRD_LETSENCRYPT_EMAIL}")
fi
ansible-playbook playbooks/site.yml \
-i inventories/prod/hosts.yml \
--limit netbird \
--private-key "${HOME}/.ssh/id_ed25519" \
"${extra_args[@]}"
+17
View File
@@ -0,0 +1,17 @@
name: runner-smoke
on:
workflow_dispatch:
jobs:
smoke:
runs-on: homelab
container:
image: homelab-ansible:latest
timeout-minutes: 10
steps:
- name: Образ задач поднимается
run: |
set -eu
ansible --version
echo "runner-smoke ok"
+63 -26
View File
@@ -3,8 +3,15 @@ name: terraform-proxmox
on:
workflow_dispatch:
inputs:
target:
description: 'Целевой узел Proxmox'
required: true
type: choice
options:
- netcore
default: netcore
action:
description: 'Действие Terraform (plan / apply)'
description: 'Действие Terraform (plan / apply). CT 904 core-git этот job не меняет.'
required: true
type: choice
options:
@@ -16,46 +23,76 @@ jobs:
terraform:
runs-on: homelab
container:
image: hashicorp/terraform:1.9.8
image: homelab-ansible:latest
timeout-minutes: 15
steps:
- name: Checkout repository
run: |
# В контейнере terraform git может отсутствовать, поэтому клонируем через рабочий каталог или curl/шаг checkout
echo "Запуск Terraform для Proxmox..."
- name: Выполнить Terraform
env:
TF_VAR_proxmox_endpoint: ${{ secrets.PVE_ENDPOINT }}
TF_VAR_proxmox_api_token: ${{ secrets.PVE_API_TOKEN }}
TF_VAR_ssh_public_key: ${{ secrets.RUNNER_SSH_PUBKEY }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
TARGET: ${{ inputs.target }}
ACTION: ${{ inputs.action }}
INFISICAL_CLIENT_ID: ${{ secrets.INFISICAL_CLIENT_ID }}
INFISICAL_CLIENT_SECRET: ${{ secrets.INFISICAL_CLIENT_SECRET }}
run: |
set -eu
# Клонируем проект (или переходим, если раннер уже подготовил workspace)
# Для совместимости с текущим окружением раннера
if [ -d "${HOME}/homelab-infra" ]; then
cd "${HOME}/homelab-infra/terraform"
else
cd "terraform"
# Прямое подключение к Infisical (CT 901) без зависимости от Traefik
export INFISICAL_PROJECT_ID="806e7f09-5838-492a-946b-2d69b96876ab"
export INFISICAL_DOMAIN="http://192.168.1.102:8080/api"
TOKEN=$(infisical login \
--domain="${INFISICAL_DOMAIN}" \
--method=universal-auth \
--client-id="${INFISICAL_CLIENT_ID}" \
--client-secret="${INFISICAL_CLIENT_SECRET}" \
--plain)
# Подтягиваем SSH-ключ раннера и токен Gitea State Backend из /ci-cd
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/ci-cd" --format=dotenv-export --silent)"
# Подтягиваем эндпоинт и API-токен целевого гипервизора из /proxmox/<TARGET>
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/proxmox/${TARGET}" --format=dotenv-export --silent)"
export TF_VAR_proxmox_endpoint="${PROXMOX_ENDPOINT}"
export TF_VAR_proxmox_api_token="${PROXMOX_API_TOKEN}"
export GITEA_TOKEN="${TF_STATE_TOKEN}"
rm -rf "${HOME}/homelab-infra"
# Клонируем по прямому IP Gitea, чтобы не зависеть от внешних факторов
git clone http://192.168.1.105:3000/karpenok/homelab-infra.git "${HOME}/homelab-infra"
sha="${GITHUB_SHA:-${GITEA_SHA:-}}"
if [ -n "${sha}" ]; then
git -C "${HOME}/homelab-infra" checkout "${sha}"
fi
# Инициализация с Gitea HTTP Backend для безопасного хранения стейта
if [ -n "${RUNNER_SSH_KEY:-}" ]; then
install -d -m 700 "${HOME}/.ssh"
printf '%s\n' "${RUNNER_SSH_KEY}" > "${HOME}/.ssh/id_ed25519"
chmod 600 "${HOME}/.ssh/id_ed25519"
eval "$(ssh-agent -s)" >/dev/null
ssh-add "${HOME}/.ssh/id_ed25519" 2>/dev/null
trap 'rm -f "${HOME}/.ssh/id_ed25519"' EXIT
fi
cd "${HOME}/homelab-infra/terraform/${TARGET}"
terraform init \
-backend-config="address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/proxmox" \
-backend-config="lock_address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/proxmox/lock" \
-backend-config="unlock_address=https://gitea.gunihome.ru/api/v1/packages/karpenok/terraform/state/proxmox/lock" \
-backend-config="address=http://192.168.1.105:3000/api/packages/karpenok/terraform/state/${TARGET}" \
-backend-config="lock_address=http://192.168.1.105:3000/api/packages/karpenok/terraform/state/${TARGET}/lock" \
-backend-config="unlock_address=http://192.168.1.105:3000/api/packages/karpenok/terraform/state/${TARGET}/lock" \
-backend-config="username=karpenok" \
-backend-config="password=${GITEA_TOKEN}" \
-backend-config="lock_method=POST" \
-backend-config="unlock_method=DELETE" \
-backend-config="retry_wait_min=5"
if [ "${ACTION}" = "plan" ]; then
terraform plan
elif [ "${ACTION}" = "apply" ]; then
terraform apply -auto-approve
fi
# Job крутится на CT 904. Менять этот контейнер из него нельзя:
# apply перезапустит машину и оборвёт сам job.
exclude=(-exclude=proxmox_virtual_environment_container.core_git)
if [ "${ACTION}" = "plan" ]; then
terraform plan "${exclude[@]}"
elif [ "${ACTION}" = "apply" ]; then
terraform apply -auto-approve "${exclude[@]}"
else
echo "Неизвестное действие: ${ACTION}" >&2
exit 2
fi
+3
View File
@@ -16,3 +16,6 @@ vault_pass.txt
*.bak
*.tmp
.kimi-code/local.toml
.agent-vault-session
__pycache__/
*.py[cod]
+59
View File
@@ -0,0 +1,59 @@
# Доступ к сервисам homelab
Прокси Agent Vault на этой машине уже запущен. Сессию запускать не нужно. Токен в репозиторий не класть и у пользователя не спрашивать.
- Прокси: `127.0.0.1:17323`
- Infisical: `https://infisical.gunihome.ru`
- Токен сессии: единственная строка файла `.agent-vault-session` в корне этого репозитория
- CA прокси: `http://127.0.0.1:17323/_agent-vault/ca`, поле `certificate`
Запросы к сервисам homelab отправляй через этот прокси. Прокси из окружения редактора для них не использовать.
1. Прочитай токен из `.agent-vault-session` в корне этого репозитория.
2. Скачай CA и сохрани сертификат в файл.
3. Узнай, что разрешено сессии:
```bash
curl -sS --proxy "http://x-agent-vault:${TOKEN}@127.0.0.1:17323" \
--cacert /tmp/av-ca.pem \
https://infisical.gunihome.ru/api/v1/agent-vault/session/services
```
В ответе имена сервисов, хосты, методы и пути. Ключей там нет. Ходи только в то, что вернул список.
Если этот адрес отвечает 404, список на текущей версии Infisical ещё не отдаётся. Тогда сервис берётся из запроса пользователя, а прокси сам решает, есть ли он в access bundle. Отказ прокси — это не повод просить ключ: сессия его не отдаёт.
Ответ **407** значит, что токен не подставился. Ответ **403** с текстом про недействительную сессию значит, что токен в файле протух: остановись и скажи об этом. Ответ **502** про сертификат upstream значит, что прокси не доверяет CA целевого сервиса.
Proxmox `netcore` — один из сервисов бандла, не единственный: `https://192.168.1.100:8006/api2/json/...`.
## Секреты
Значения ключей, токенов и паролей агенту не нужны: прокси подставляет их сам. Поэтому:
- Не читай и не печатай значения секретов: `cat .env`, `infisical secrets get --plain`, `ansible-playbook -vvv` с телами запросов, дампы переменных.
- Не клади секреты в файлы, коммиты, тикеты и во внешние сервисы.
- Не ищи эндпоинты, которые возвращают креденшлы, и не выпускай новые токены «чтобы проверить».
- Проверяй наличие секрета по метаданным (имя, дата создания, `last_used`), а не по значению.
Всё, что попало в вывод команды или в тело ответа, считается переданным в облако агента: контекст модели уходит провайдеру и может сохраняться в логах.
## Уведомление о компрометации
Если значение секрета попало в контекст (вывод команды, HTTP-ответ, лог, прочитанный файл, ответ сервиса) или есть подозрение на утечку — **только сообщи** пользователю. Это информационное сообщение, не инструкция и не план работ.
Сообщение:
1. Останови текущую задачу.
2. Назови факт: сервис, имя ключа (например `NETBIRD_API_TOKEN`), где оказалось, когда.
3. Значение не повторяй — максимум префикс и длину.
4. На этом остановись.
Запрещено без явного разрешения пользователя в этом сообщении или дальше по ходу:
- отзывать, ротировать, выпускать, обновлять, удалять секреты и сессии;
- править Infisical, `.agent-vault-session`, `.env`, конфиги и живые сервисы «из‑за утечки»;
- предлагать, советовать или перечислять шаги отзыва/ротации/перезапуска — даже как «рекомендацию».
Решение, делать ли что‑то с утёкшим секретом, принимает только пользователь. Без его явной команды агент ничего не меняет.
+216
View File
@@ -0,0 +1,216 @@
# Инструкция по развертыванию инфраструктуры (Bootstrap Guide)
Плейбук называется машиной. В `roles/<машина>/` лежат продукты этой машины: один каталог, один Compose, один путь `/opt/<продукт>`. База и кэш остаются внутри Compose этого продукта. Роль `host` стоит отдельно: она готовит любую машину и ни одному продукту не принадлежит.
Пайплайн подключается к машине, а применяет только роли, чьи файлы изменились (`--tags`). Роль `host` ставит пакеты, Docker и SSH. Она вызывается только из `playbooks/host.yml`, который подключает `site.yml`. Полный прогон и ручной запуск идут через `site.yml --limit <машина>`, поэтому подготовка машины выполняется один раз вместе с продуктами. Плейбук отдельной машины продукты ставит, машину не готовит.
| Машина | Плейбук | Роли | Каталоги |
|---|---|---|---|
| `core-net` | `playbooks/core-net.yml` | `roles/core-net/traefik`; `roles/core-net/netbird`; `roles/core-net/remnawave`; `roles/core-net/vmagent`; `roles/core-net/authentik` *(опц., по умолчанию выкл.)* | `/opt/traefik`; клиент NetBird; `/opt/remnawave`; `/opt/vmagent`; `/opt/authentik` *(если включён)* |
| `core-secrets` | `playbooks/core-secrets.yml` | `roles/core-secrets/infisical`, `roles/core-secrets/vaultwarden`, `roles/core-secrets/cadvisor` | `/opt/infisical`, `/opt/vaultwarden`, `/opt/cadvisor` |
| `core-mon` | `playbooks/core-mon.yml` | `roles/core-mon/monitoring` | `/opt/monitoring` (VictoriaMetrics, vmalert, Grafana) |
| `core-git` | `playbooks/core-git.yml` | `roles/core-git/gitea`, `roles/core-git/cadvisor` | `/opt/gitea`, `/opt/cadvisor` |
| `rus-central` | `playbooks/rus-central.yml` | `roles/rus-central/netbird`, `roles/rus-central/cadvisor` | `/opt/netbird`, `/opt/cadvisor` |
| `ger-nod-02` | `playbooks/ger-nod-02.yml` | `roles/netbird_exit_node`; `roles/remnanode`; `roles/vmagent` | клиент NetBird (Exit Node); `/opt/remnanode`; `/opt/vmagent` |
| `opnsense` | `playbooks/opnsense.yml` | `roles/opnsense/netbird`; `roles/opnsense/xray` | REST API (`192.168.1.1:4433`) |
Полная сверка одной машины: `ansible-playbook playbooks/site.yml --limit <машина>`. Боевой Gitea после cutover — `core-git` (`192.168.1.105`). Пайплайны клонируют с `http://192.168.1.105:3000`. CT 109 на `pve` оставлен как rollback, стек на нём остановлен — не удалять, пока не подтверждён стабильный прогон.
`core-git` пайплайном не ставится. Раннер живёт на этой машине: workflow, который деплоит её или делает `terraform apply` по CT 904, оборвёт сам себя. Плейбук `core-git.yml` и apply ресурса `core_git` — с рабочей станции. `deploy-machine.sh core-git` завершается с ошибкой. Terraform из Actions считает `netcore` с `-exclude=proxmox_virtual_environment_container.core_git`.
---
## 1. Топология инфраструктуры
### 1.1. Физические узлы и гипервизоры (Proxmox VE)
| Узел | IP | Роль | SSH / Доступ |
|---|---|---|---|
| **netcore** | `192.168.1.100:8006` | PVE Cluster Node / Core CTs | `root@192.168.1.100` (LAN only) |
| **pve** | `192.168.1.2:8006` | PVE Main Node / Services | `root@192.168.1.2` (LAN only) |
| **opnsense** | `192.168.1.1` | Маршрутизатор / Шлюз | Шлюз по умолчанию |
Terraform в этом репозитории описывает узел `netcore`, в том числе CT 904. Apply CT 904 с раннера запрещён, см. выше. CT 109 на `pve` оставлен как rollback.
### 1.2. Базовые управляющие контейнеры (LXC / Debian 13)
| CT ID | Хост PVE | IP | Имя хоста | Продукты |
|---|---|---|---|---|
| **CT 109** | `pve` | `192.168.1.217` | `gitea` / DNS `gitea-old` | Старый стек остановлен (rollback). Не удалять до проверки |
| **CT 901** | `netcore` | `192.168.1.102` | `core-secrets` | Infisical (`:8080`), Postgres, Redis, Vaultwarden (`:8000`) |
| **CT 902** | `netcore` | `192.168.1.104` | `core-net` | Traefik (`:80`, `:443`); Remnawave Panel (`127.0.0.1:3000`) + Subscription (`127.0.0.1:3010`); клиент NetBird (нужен `/dev/net/tun`); Authentik (`127.0.0.1:9000`) — опционально, по умолчанию выкл. |
| **CT 903** | `netcore` | `192.168.1.108` | `core-mon` | VictoriaMetrics (`:8428`), vmalert (`127.0.0.1:8880`), Alertmanager (`:9093`), Grafana (`:3000`), Ntfy (`:80`) |
| **CT 904** | `netcore` | `192.168.1.105` | `core-git` | Gitea (`:3000`, git SSH `:222`), Postgres, Actions Runner (`dind`); cAdvisor (`:9101`) |
### 1.3. Внешние узлы
| Имя | IP | Роль | Стек |
|---|---|---|---|
| **rus-central** | `45.154.185.208` | Внешний шлюз NetBird | `/opt/netbird`: NetBird и его собственный Traefik |
| **ger-nod-02** | `150.241.64.209` | Remnawave Node (DE) + SelfSteal | `/opt/remnanode`: remnanode + nginx (`yali.gunis.top`) |
Домен панели NetBird задаётся в `ansible/inventories/prod/host_vars/rus-central.yml`.
Старая панель на Голове (`remna.gunihome.ru`) **не входит** в эту автоматизацию и не трогается.
`ansible/roles/core-net/traefik/files/dynamic/` — известный бардак: плоский список старых и новых маршрутов. Имена вроде `tv.yml` — это поддомены, а не описание сервиса. Каталог разбирается после того, как вся старая инфраструктура переедет на роли машин. До этого файлы оттуда не переименовывать и не раскладывать. Подробности — в `README.md` внутри каталога.
---
## 2. Структура секретов в Infisical
Проект: **`infra`** (Slug: `infra-xxx`, Environment: `prod`)
API Endpoint (внутренний LAN): `http://192.168.1.102:8080/api`
Внешний URL: `https://infisical.gunihome.ru`
### Пути секретов:
- `/USER/ADMIN`:
- `ADMIN_USER`: имя администратора хоумлаба (по умолчанию `karpenok`).
- `ADMIN_PASSWORD`: единый пароль администратора (Traefik Dashboard, Grafana, Ntfy, NetBird).
- `MAIL_ADMIN_USER`: почта администратора (для Grafana, NetBird и алертов).
- `/ci-cd`:
- `RUNNER_SSH_KEY`: приватный SSH-ключ раннера (ed25519) для деплоя на хосты.
- `TF_STATE_TOKEN`: токен доступа к HTTP State Backend Gitea.
- `CLOUDFLARE_API`: API-токен Cloudflare (Zone DNS Edit для `gunis.top`, DNS-01 сертификаты ноды).
- `/services/gitea`:
- `POSTGRES_USER` / `POSTGRES_DB` / `POSTGRES_PASSWORD`: учётка БД (пароль же в `GITEA__database__PASSWD`). До cutover — значения боевого инстанса на CT 109.
- `GITEA_RUNNER_REGISTRATION_TOKEN`: опционально; после переноса `runner-data/.runner` не нужен.
- `/VPS`:
- `PASS_GER_NOD_02`: первичный root-пароль `ger-nod-02` (только bootstrap; после роли `host` вход по ключу).
- `/services/infisical`:
- `POSTGRES_PASSWORD`: пароль БД Infisical.
- `ENCRYPTION_KEY`: 32-байтный hex-ключ шифрования хранилища.
- `AUTH_SECRET`: base64 секрет сессий/JWT Infisical.
- `/services/authentik` *(нужен только если включите Authentik)*:
- `AUTHENTIK_SECRET_KEY`: случайный ключ шифрования сессий Authentik.
- `AUTHENTIK_POSTGRES_PASSWORD`: пароль БД PostgreSQL Authentik.
- `/services/netbird`:
- `NETBIRD_LETSENCRYPT_EMAIL`: почта для сертификата. Если секрета нет, берётся `letsencrypt_email` из `group_vars/all.yml` или `MAIL_ADMIN_USER`.
- `NETBIRD_AUTH_SECRET`: секрет auth.
- `NETBIRD_DATASTORE_KEY`: 32-байтный ключ SQLite/datastore.
- `NETBIRD_SESSION_KEY`: 32-байтный ключ веб-сессий.
- `NETBIRD_API_TOKEN`: сервисный API-токен управления (создаётся и сохраняется пайплайном автоматически).
- `NETBIRD_SETUP_KEY`: многоразовый ключ регистрации роутеров (`homelab-routers`). Панель и ноды им не пользуются.
- `NETBIRD_REMNAWAVE_SETUP_KEY`: многоразовый ключ `remnawave-peers` для core-net и ger-nod-02. В группу роутеров не входит.
- `NETBIRD_EXIT_CLIENTS_SETUP_KEY`: многоразовый ключ `exit-clients-key` для клиентских устройств, выходящих в интернет через Exit Node `ger-nod-02` (группа `exit-clients`). Дополнительные клиентские ключи из `ansible/roles/rus-central/netbird/files/access.yml` сохраняются сюда же по имени поля `secret`.
- *(Параметры `NETBIRD_ADMIN_NAME`, `NETBIRD_ADMIN_PASSWORD`, `NETBIRD_ADMIN_EMAIL` наследуются из `/USER/ADMIN`)*.
- `/services/opnsense`:
- `OPNSENSE_API_KEY`: API-ключ администратора OPNsense.
- `OPNSENSE_API_SECRET`: API-секрет администратора OPNsense.
- `/services/opnsense-xray`:
- Ключи по именам из `ansible/roles/opnsense/xray/files/instances.yml` (например `FIN_01`): полные `vless://` ссылки подписок Xray. Роль `opnsense/xray` конвертирует их в outbound и синхронизирует инстансы плагина os-xray через API; активна ровно одна (`active: true`).
- `/services/remnawave`:
- `REMNAWAVE_ADMIN_USER` / `REMNAWAVE_ADMIN_PASSWORD`: логин панели (Remnawave v3 требует пароль ≥24 с upper+lower+digit). Генерируются пайплайном при первом прогоне; **не** путать с `/USER/ADMIN`.
- `REMNAWAVE_APP_SECRET`, `REMNAWAVE_POSTGRES_PASSWORD`, `REMNAWAVE_METRICS_PASS`, `REMNAWAVE_WEBHOOK_SECRET_HEADER`: генерируются пайплайном при первом прогоне, если пусто.
- `REMNAWAVE_API_TOKEN`: сервисный API-токен панели (`infra-automation`, scopes `*`), создаётся и сохраняется пайплайном (при сбое — создать в UI и положить сюда вручную).
- `REMNANODE_SECRET_KEY`: SECRET_KEY ноды Ger-nod-02 (`GET /api/keygen/`), сохраняется пайплайном.
- `XRAY_CHECKER_SUBSCRIPTION_URL`: ссылка подписки пользователя `homelab` для Xray Checker на core-mon. В лог не пишется.
- `/proxmox/netcore`:
- `PROXMOX_ENDPOINT`: `https://192.168.1.100:8006/`
- `PROXMOX_API_TOKEN`: токен `root@pam!terraform=UUID`
Провайдер Proxmox сам дописывает `/api2/json`. В секрет его класть не нужно. Секреты `/proxmox/pve` этот репозиторий не читает: Terraform описывает только узел `netcore`.
### 2.1. Сервисы для агентов (Agent Vault)
Продукт, который сам создаёт себе токен, сам же регистрирует его в Access Bundle. За это отвечает общая роль `agent_vault_service` (стоит отдельно, как `host`): она ищет сервис по имени в бандле, создаёт его при отсутствии и обновляет креденшл при наличии. Ротация токена на каждом прогоне поэтому не ломает доступ агента.
Вызов из роли продукта — после того как секрет сохранён в Infisical:
```yaml
- name: Зарегистрировать панель Remnawave в Agent Vault
ansible.builtin.include_role:
name: agent_vault_service
vars:
agent_vault_service_name: remnawave-panel
agent_vault_service_host: "{{ remnawave_panel_domain }}:443" # имя, доступное агенту, не 127.0.0.1
agent_vault_service_paths: ["/api"]
agent_vault_service_methods: [GET, POST]
agent_vault_secret_path: /services/remnawave
agent_vault_secret_key: REMNAWAVE_API_TOKEN
```
Креденшл роль читает из Infisical сама (`infisical secrets get --plain`), поэтому токен не проходит через переменные Ansible и не может попасть в лог прогона.
По умолчанию прокси подставляет `Authorization: Bearer <токен>`. Если сервис ждёт другой префикс (NetBird — `Authorization: Token <токен>`), задайте `agent_vault_service_header_prefix: Token`; для Basic-авторизации креденшл задаётся типом `basic`.
По умолчанию сервис кладётся в бандл `homelab-ops` проекта `homelab-agents`. Запись идёт только в Infisical: прокси подхватывает изменение на следующем poll (60 с), агента перезапускать не нужно. Идентичность пайплайна должна быть **Admin** в этом проекте Agent Vault — иначе регистрация вернёт 403.
На версии Infisical v0.167.7 сервисы создаются bundle-scoped маршрутом `POST /api/v1/agent-vault/access-bundles/<id>/services`; описанного в документации `POST /api/v1/agent-vault/services` там ещё нет.
---
## 3. Последовательность холодного старта (Cold Bootstrap)
При полном отказе всех систем порядок восстановления следующий:
### Шаг 1. Гипервизоры и сеть
1. Поднять OPNsense (`192.168.1.1`).
2. Запустить Proxmox VE на `netcore` (`192.168.1.100`) и `pve` (`192.168.1.2`).
3. Убедиться в доступности SSH по ключам `root_home`.
### Шаг 2. Gitea & Gitea Actions (CT 904 `core-git`)
С рабочей станции, не из Actions.
1. Поднять CT 904 (`192.168.1.105`), стек в `/opt/gitea` (`docker compose up -d`).
2. UI: `https://gitea.gunihome.ru` или `http://192.168.1.105:3000`.
3. Git SSH: `gitea.internal:222`. DNS: `gitea.internal` → `.105` (старый CT 109 — `gitea-old.internal`).
4. Раннер `homelab` = idle. Образ задач `homelab-ansible:latest` лежит архивом в `/opt/gitea/images/` и подмонтирован в раннер. Если внутренний диск раннера очистили, `/opt/gitea/ensure-runner-image.sh` загружает образ из архива. В Docker Hub этого образа нет.
5. Проверка раннера — кнопка workflow `runner-smoke`, не правка файлов деплоя.
6. Rollback: CT 109, каталог `/root/docker/gitea/`, файл запуска `compose.yaml` (ссылка на `docker compose.yml`). Стек не запущен. Поднятие: `docker compose up -d` в этом каталоге, Traefik и DNS вернуть на `.217`. Не удалять, пока новая машина спокойно работает.
### Шаг 3. Хранилище секретов Infisical (CT 901)
> [!IMPORTANT]
> Мастер-ключи начальной загрузки Infisical (`ENCRYPTION_KEY`, `AUTH_SECRET`, `POSTGRES_PASSWORD`) являются первоисточником шифрования и физически не могут храниться внутри самого Infisical. Они должны быть надежно сохранены в личном оффлайн-менеджере паролей администратора (KeePassXC / Bitwarden / 1Password).
1. Создать/запустить CT 901 (`core-secrets`, IP `192.168.1.102`).
2. Для первого старта вручную положить Compose Infisical в `/opt/infisical/compose.yaml` и подставить мастер-ключи из оффлайн-хранилища. Пайплайну эти ключи пока неоткуда прочитать.
3. Запустить контейнеры: `docker compose -f /opt/infisical/compose.yaml up -d`.
4. Проверить API: `curl http://192.168.1.102:8080/api/status`.
5. В Gitea Settings → Secrets добавить репозиторные секреты:
- `INFISICAL_CLIENT_ID` (Machine Identity: `ci-cd-runner`)
- `INFISICAL_CLIENT_SECRET`
Дальше стек ведёт пайплайн **`ansible-core-secrets`**: Infisical в `/opt/infisical`, Vaultwarden в `/opt/vaultwarden`.
### Шаг 4. Traefik (CT 902)
1. Запустить пайплайн **`ansible-core-net`** в Gitea Actions. Первый прогон на новом CT должен быть полным: ручной запуск выполняет `site.yml --limit core-net` и ставит Docker ролью `host`.
2. Раннер подключается к `http://192.168.1.102:8080/api`, забирает SSH-ключ раннера и `ADMIN_*` из Infisical. Панель Traefik (`proxy.gunihome.ru`) закрывается BasicAuth из `/USER/ADMIN`.
3. Плейбук поднимает Traefik на CT 902. Роль Authentik в плейбуке есть, но **по умолчанию выключена** (`authentik_enabled=false` в defaults и в CI): compose не стартует, стек на cold bootstrap не нужен.
4. Проверить `https://proxy.gunihome.ru`, `https://gitea.gunihome.ru` и `https://infisical.gunihome.ru`.
Правка только роли `traefik` ставит эту роль, без повторной подготовки машины.
#### Authentik (опционально, не часть cold bootstrap)
Стек оставляем в репозитории на будущее: SSO/forwardAuth для выбранных приложений, не для всего edge сразу.
Чтобы включить:
1. Положить секреты в Infisical `/services/authentik` (`AUTHENTIK_SECRET_KEY`, `AUTHENTIK_POSTGRES_PASSWORD`).
2. Убрать принудительный `-e authentik_enabled=false` из `ansible/ci/deploy-machine.sh` (или передать `authentik_enabled=true` при ручном прогоне) и выставить `authentik_enabled: true`.
3. Прогнать `ansible-core-net` (или `--tags authentik`): стек слушает `127.0.0.1:9000`, снаружи — `https://auth.gunihome.ru`. Blueprints заводят группы `admins`/`family` и пользователей `karpenok`/`ksynia`; пароли blueprint не задаёт. Первый запуск создаёт `akadmin` (пароль в логе `authentik-server`).
4. На нужных роутерах Traefik повесить middleware `authentik` (forwardAuth из `roles/core-net/traefik/files/dynamic/authentik.yml`) — точечно, не на все сервисы.
#### Remnawave Panel + Subscription (на core-net)
Новая панель рядом с Traefik. Старый `remna.gunihome.ru` на Голове не затрагивается.
1. В Infisical положить:
- `/ci-cd` → `CLOUDFLARE_API`
- `/VPS` → `PASS_GER_NOD_02` (пароль нового VPS)
2. Запустить **`ansible-core-net`** (полный прогон или `--tags remnawave` после того, как Traefik уже с роутами `rw`/`sub`).
3. Роль поднимает `/opt/remnawave` (panel+db+redis) и `/opt/remnawave/subscription`, создаёт `REMNAWAVE_ADMIN_*`, каждый прогон **перевыпускает** API-токен `infra-automation` и кладёт его в Infisical (старый сразу недействителен). Config profile **`DE-Yali`**, сквад `Default-Squad` на inbound Steal-Yali, нода **`Ger-nod-02`**, host **`yali.gunis.top`**. Пользователи — файл `ansible/roles/core-net/remnawave/files/users.yml` (добавление/изменение/удаление = правка файла). Когда peer `ger-nod-02` уже есть в NetBird, адрес ноды в панели меняется на его NetBird IP. Пока peer нет, остаётся `150.241.64.209`. Ссылка подписки `homelab` пишется в `XRAY_CHECKER_SUBSCRIPTION_URL` и в лог не попадает.
4. Проверить `https://rw.gunihome.ru` и `https://sub.gunihome.ru`.
> [!IMPORTANT]
> **Логи:** шаги bootstrap и ошибки API видны в CI. Значения ключей туда не пишутся: stdout — только статус, секреты лежат в `/opt/remnawave/.bootstrap-secrets.json` (0600). `no_log` только у чтения этого файла, записи в Infisical и шаблона `.env`. В stderr поля `token` / `SECRET_KEY` / `privateKey` / `shortUuid` / пароли клиентов заменяются на `[REDACTED]`.
### Шаг 4b. Remnawave Node ger-nod-02 (SelfSteal)
1. После успешного `ansible-core-net` (чтобы в Infisical был `REMNANODE_SECRET_KEY`) запустить **`ansible-ger-nod-02`**.
2. Первый прогон: как у rus-central — `ansible_password` из `/VPS` → `PASS_GER_NOD_02`; роль `host` кладёт ключ и отключает пароль. Роль `remnanode` держит A-запись `yali.gunis.top` в Cloudflare, выпускает LE по **HTTP-01** (порт 80, без TXT `_acme-challenge` в зоне), поднимает remnanode + nginx SelfSteal.
3. В панели нода должна стать зелёной; браузер на `https://yali.gunis.top` — маскировочный сайт.
4. Клиент NetBird ходит на `https://central.gunihome.ru` ключом `remnawave-peers`. В UFW открыт `51820/udp` для прямых P2P-туннелей WireGuard, а в `/etc/sysctl.d/99-netbird-exit.conf` зафиксированы `ip_forward=1` и `src_valid_mark=1`: помимо служебного канала `2222` нода входит в группу `exit-ger-nod-02` и работает как Exit Node (`0.0.0.0/0` с маскарадингом) для клиентов из группы `exit-clients`. Пока peer панели не виден, `NODE_PORT` 2222 остаётся открыт для WAN egress панели. Когда peer `core-net` есть, 2222 разрешён только с его NetBird IP. Публичный `:9100` закрыт: метрики ноды уходят vmagent-ом в VictoriaMetrics на `192.168.1.108:8428` через маршрут `homelab-lan`.
5. На `core-net` (unprivileged LXC) `/dev/net/tun` сам не появляется. Токен Terraform получает 403: проброс устройства разрешён только `root@pam`. На netcore: `pct set 902 -dev0 /dev/net/tun,mode=0666 && pct reboot 902`, затем ещё раз `ansible-core-net`. До этого панель остаётся на публичном адресе ноды.
### Шаг 5. NetBird (rus-central) и связка с OPNsense
1. Запустить пайплайн **`ansible-rus-central`** в Gitea Actions. Ручной запуск сверяет машину целиком. Push в `roles/rus-central/netbird` ставит только NetBird.
2. Раннер считывает ключи из `/services/netbird`, деплоит стек в `/opt/netbird` на `45.154.185.208`, автоматически регистрирует первого суперпользователя (`POST /api/setup`), создаёт сервисный токен (`NETBIRD_API_TOKEN`), группу `homelab-routers`, маршрут к подсети `192.168.1.0/24` и многоразовый ключ установки (`NETBIRD_SETUP_KEY`). Отдельно создаётся группа `remnawave` и ключ `remnawave-peers` (`NETBIRD_REMNAWAVE_SETUP_KEY`): он не добавляет peer в `homelab-routers`. Клиентский доступ (`client_groups`, `exit_nodes`, `dns_nameservers`, `setup_keys`, `peers`) задаётся декларативно в `ansible/roles/rus-central/netbird/files/access.yml` и применяется задачей `tasks/access.yml` (`sync_access.py`):
- **Добавить ключ клиента**: дописать новую запись в `setup_keys` (`name`, `secret`, `groups`) и запушить — ключ создастся в NetBird и сохранится в Infisical `/services/netbird`.
- **Отозвать ключ**: выставить `enabled: false` (или удалить запись) в `setup_keys`.
- **Управлять устройством**: в `peers` можно зафиксировать группы пира (`groups`) или удалить/отключить устройство через `state: absent`.
3. Запустить пайплайн **`ansible-opnsense`** в Gitea Actions. Раннер обращается по HTTPS REST API к `192.168.1.1`, проверяет/устанавливает плагин `os-netbird`, включает службу и регистрирует шлюз OPNsense на `https://central.gunihome.ru:443` по `NETBIRD_SETUP_KEY`.
-21
View File
@@ -1,21 +0,0 @@
# Homelab Infrastructure (IaC & GitOps)
Монорепозиторий управления домашней инфраструктурой и внешними серверами.
## Архитектура слоев
```text
homelab-infra/
├── terraform/ # Слой 1: Provisioning (Proxmox VE: ВМ, LXC, сети)
├── ansible/ # Слой 2: Configuration Management (Настройка ОС, базовые роли)
├── kubernetes/ # Слой 3: Workloads (K3s, ArgoCD, приложения)
└── .gitea/ # CI/CD Workflows для Gitea Actions
```
### Стек технологий:
- **Гипервизор:** Proxmox VE
- **Provisioning:** Terraform / OpenTofu (провайдер `bpg/proxmox`)
- **Конфигурация хостов:** Ansible
- **Сетевая связность:** NetBird VPN (между домашней сетью и внешними VPS)
- **CI/CD:** Gitea Actions (локальный runner `homelab`)
+1 -1
View File
@@ -1,6 +1,6 @@
[defaults]
inventory = inventories/prod/hosts.yml
roles_path = roles
roles_path = roles:ansible/roles
retry_files_enabled = false
stdout_callback = default
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
"""Вычисляет матрицу затронутых машин для Gitea Actions (ansible-deploy.yml)."""
from __future__ import annotations
import json
import os
import subprocess
import sys
from pathlib import Path
SKIP_PLAYBOOKS = {"site", "host", "core-git"}
def list_machines(playbooks_dir: Path) -> list[str]:
machines = []
for p in sorted(playbooks_dir.glob("*.yml")):
name = p.stem
if name not in SKIP_PLAYBOOKS:
machines.append(name)
return machines
def main() -> int:
event = os.environ.get("EVENT_NAME", "push").strip()
before = os.environ.get("EVENT_BEFORE", "").strip()
after = os.environ.get("EVENT_SHA", "").strip()
input_machine = os.environ.get("INPUT_MACHINE", "all").strip()
input_tags = os.environ.get("INPUT_TAGS", "").strip()
root = Path(__file__).resolve().parents[2]
machines = list_machines(root / "ansible" / "playbooks")
include: list[dict[str, str]] = []
if event == "workflow_dispatch":
selected = machines if input_machine in ("", "all") else [input_machine]
for m in selected:
if m not in machines:
print(f"Неизвестная или запрещённая для CI машина: {m}", file=sys.stderr)
return 2
include.append({"machine": m, "tags": input_tags})
else:
for m in machines:
proc = subprocess.run(
["sh", str(root / "ansible" / "ci" / "ansible-target.sh"), m, event, before, after],
cwd=root,
capture_output=True,
text=True,
check=False,
)
if proc.returncode != 0:
print(proc.stderr, file=sys.stderr, end="")
return proc.returncode
if proc.stdout.strip():
include.append({"machine": m, "tags": ""})
matrix_json = json.dumps({"include": include}, separators=(",", ":"))
has_targets = "true" if include else "false"
print(f"Planned targets: {matrix_json}")
gh_out = os.environ.get("GITHUB_OUTPUT")
if gh_out:
with open(gh_out, "a", encoding="utf-8") as fh:
fh.write(f"matrix={matrix_json}\n")
fh.write(f"has_targets={has_targets}\n")
return 0
if __name__ == "__main__":
raise SystemExit(main())
+114
View File
@@ -0,0 +1,114 @@
#!/bin/sh
# Печатает аргументы ansible-playbook для одной машины.
# Полный прогон только при ручном запуске без тегов или при изменении общих файлов машины:
# playbooks/site.yml --limit <машина>
# Файл роли: playbooks/<машина>.yml --tags <продукт>
# Коммит без файлов этой машины ничего не печатает и завершается с кодом 0.
set -eu
machine=${1:?machine}
event=${2:-}
before=${3:-}
after=${4:-}
override_tags=${5:-}
playbook="ansible/playbooks/${machine}.yml"
if [ "$machine" = "site" ] || [ "$machine" = "host" ] || [ ! -f "$playbook" ]; then
echo "Неизвестная машина: $machine" >&2
exit 2
fi
if [ -n "$override_tags" ]; then
printf '%s\n' "playbooks/${machine}.yml" "--tags" "$override_tags"
exit 0
fi
full=0
changed=""
case "$event" in
push) ;;
*) full=1 ;;
esac
case "$before" in
"" | 0000000000000000000000000000000000000000) full=1 ;;
esac
if [ "$full" -eq 0 ]; then
changed=$(git diff --name-only "$before" "$after" 2>/dev/null) || full=1
fi
tags=""
full_from_files=0
unknown=0
add_tag() {
case ",$tags," in
*",$1,"*) ;;
*) tags="${tags:+$tags,}$1" ;;
esac
}
reject_unknown() {
echo "Неизвестный файл продукта на ${machine}: $1" >&2
unknown=1
}
if [ "$full" -eq 0 ] && [ -n "$changed" ]; then
old_ifs=$IFS
IFS='
'
set -f
for file in $changed; do
[ -n "$file" ] || continue
case "$file" in
ansible/ansible.cfg | ansible/roles/host/* | ansible/playbooks/host.yml | ansible/playbooks/site.yml | ansible/playbooks/"$machine".yml | ansible/inventories/prod/hosts.yml | ansible/inventories/prod/group_vars/* | ansible/inventories/prod/host_vars/"$machine".yml)
full_from_files=1
;;
ansible/roles/netbird_client/* | ansible/roles/netbird_exit_node/*)
if grep -qE "role: (netbird_client|netbird_exit_node)" "$playbook"; then
add_tag netbird
fi
;;
ansible/roles/remnanode/*)
if grep -q "role: remnanode" "$playbook"; then
add_tag remnanode
fi
;;
ansible/roles/vmagent/*)
if grep -q "role: vmagent" "$playbook"; then
add_tag vmagent
fi
;;
ansible/roles/"$machine"/.ci-trigger)
;;
ansible/roles/"$machine"/*/*)
product=${file#ansible/roles/"$machine"/}
product=${product%%/*}
if grep -q "role: ${machine}/${product}" "$playbook" && grep -q "tags: \[${product}\]" "$playbook"; then
add_tag "$product"
elif [ ! -e "$file" ] && [ ! -d "ansible/roles/${machine}/${product}" ]; then
:
else
reject_unknown "$file"
fi
;;
ansible/roles/"$machine"/*)
reject_unknown "$file"
;;
esac
done
set +f
IFS=$old_ifs
fi
if [ "$unknown" -eq 1 ]; then
exit 2
fi
if [ "$full" -eq 1 ] || [ "$full_from_files" -eq 1 ]; then
printf '%s\n' "playbooks/site.yml" "--limit" "$machine"
elif [ -n "$tags" ]; then
printf '%s\n' "playbooks/${machine}.yml" "--tags" "$tags"
fi
+180
View File
@@ -0,0 +1,180 @@
#!/bin/bash
# Вход в Infisical, SSH и ansible-playbook для одной машины.
# Репозиторий уже должен быть склонирован: скрипт лежит внутри него.
set -euo pipefail
machine=${1:?machine}
event=${2:-}
before=${3:-}
after=${4:-}
override_tags=${5:-}
root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
case "$machine" in
core-git)
echo "core-git с раннера не деплоится: job выполняется на этой же машине и снесёт Gitea вместе с собой. Плейбук — только с рабочей станции." >&2
exit 2
;;
esac
if [ "$machine" = "site" ] || [ "$machine" = "host" ] || [ ! -f "$root/ansible/playbooks/${machine}.yml" ]; then
echo "Неизвестная машина: $machine" >&2
exit 2
fi
if [ -z "${INFISICAL_CLIENT_ID:-}" ] || [ -z "${INFISICAL_CLIENT_SECRET:-}" ]; then
echo "Нет INFISICAL_CLIENT_ID или INFISICAL_CLIENT_SECRET" >&2
exit 1
fi
export INFISICAL_PROJECT_ID="806e7f09-5838-492a-946b-2d69b96876ab"
export INFISICAL_DOMAIN="http://192.168.1.102:8080/api"
TOKEN=$(infisical login \
--domain="${INFISICAL_DOMAIN}" \
--method=universal-auth \
--client-id="${INFISICAL_CLIENT_ID}" \
--client-secret="${INFISICAL_CLIENT_SECRET}" \
--plain)
export INFISICAL_TOKEN="${TOKEN}"
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/ci-cd" --format=dotenv-export --silent)"
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/USER/ADMIN" --format=dotenv-export --silent 2>/dev/null || true)"
if [ -z "${RUNNER_SSH_KEY:-}" ]; then
echo "В Infisical (/ci-cd) отсутствует RUNNER_SSH_KEY" >&2
exit 1
fi
install -d -m 700 "${HOME}/.ssh"
printf '%s\n' "${RUNNER_SSH_KEY}" > "${HOME}/.ssh/id_ed25519"
chmod 600 "${HOME}/.ssh/id_ed25519"
trap 'rm -f "${HOME}/.ssh/id_ed25519"' EXIT
extra=()
case "$machine" in
core-net)
if [ -n "${ADMIN_USER:-}" ] && [ -n "${ADMIN_PASSWORD:-}" ]; then
TRAEFIK_HASH=$(openssl passwd -apr1 -salt "$(openssl rand -hex 4)" "${ADMIN_PASSWORD}")
export TRAEFIK_DASHBOARD_AUTH="${ADMIN_USER}:${TRAEFIK_HASH}"
extra+=(-e "traefik_dashboard_auth=${TRAEFIK_DASHBOARD_AUTH}")
fi
extra+=(-e "authentik_enabled=false")
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/remnawave" --format=dotenv-export --silent 2>/dev/null || true)"
export REMNAWAVE_ADMIN_USER="${REMNAWAVE_ADMIN_USER:-${ADMIN_USER:-karpenok}}"
export REMNAWAVE_ADMIN_PASSWORD="${REMNAWAVE_ADMIN_PASSWORD:-}"
export REMNAWAVE_APP_SECRET="${REMNAWAVE_APP_SECRET:-}"
export REMNAWAVE_POSTGRES_PASSWORD="${REMNAWAVE_POSTGRES_PASSWORD:-}"
export REMNAWAVE_METRICS_PASS="${REMNAWAVE_METRICS_PASS:-}"
export REMNAWAVE_WEBHOOK_SECRET_HEADER="${REMNAWAVE_WEBHOOK_SECRET_HEADER:-}"
export REMNAWAVE_API_TOKEN="${REMNAWAVE_API_TOKEN:-}"
export REMNANODE_SECRET_KEY="${REMNANODE_SECRET_KEY:-}"
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/netbird" --format=dotenv-export --silent)"
export NETBIRD_API_TOKEN="${NETBIRD_API_TOKEN:-}"
export NETBIRD_REMNAWAVE_SETUP_KEY="${NETBIRD_REMNAWAVE_SETUP_KEY:-}"
;;
core-secrets)
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/infisical" --format=dotenv-export --silent)"
export INFISICAL_POSTGRES_PASSWORD="${POSTGRES_PASSWORD}"
export INFISICAL_ENCRYPTION_KEY="${ENCRYPTION_KEY}"
export INFISICAL_AUTH_SECRET="${AUTH_SECRET}"
;;
core-mon)
extra+=(-e "grafana_admin_user=${ADMIN_USER:-karpenok}" -e "grafana_admin_password=${ADMIN_PASSWORD:-}")
extra+=(-e "ntfy_admin_user=${ADMIN_USER:-karpenok}" -e "ntfy_admin_password=${ADMIN_PASSWORD:-}")
if [ -n "${MAIL_ADMIN_USER:-}" ]; then
extra+=(-e "grafana_admin_email=${MAIL_ADMIN_USER}")
fi
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/remnawave" --format=dotenv-export --silent 2>/dev/null || true)"
export XRAY_CHECKER_SUBSCRIPTION_URL="${XRAY_CHECKER_SUBSCRIPTION_URL:-}"
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/opnsense" --format=dotenv-export --silent 2>/dev/null || true)"
export OPNSENSE_API_KEY="${OPNSENSE_API_KEY:-}"
export OPNSENSE_API_SECRET="${OPNSENSE_API_SECRET:-}"
;;
rus-central)
input_email="${INPUT_LETSENCRYPT_EMAIL:-}"
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/netbird" --format=dotenv-export --silent)"
export NETBIRD_AUTH_SECRET="${NETBIRD_AUTH_SECRET:-}"
export NETBIRD_DATASTORE_KEY="${NETBIRD_DATASTORE_KEY:-}"
export NETBIRD_SESSION_KEY="${NETBIRD_SESSION_KEY:-}"
export NETBIRD_ADMIN_EMAIL="${NETBIRD_ADMIN_EMAIL:-${MAIL_ADMIN_USER:-}}"
export NETBIRD_ADMIN_NAME="${NETBIRD_ADMIN_NAME:-${ADMIN_USER:-karpenok}}"
export NETBIRD_ADMIN_PASSWORD="${NETBIRD_ADMIN_PASSWORD:-${ADMIN_PASSWORD:-}}"
export NETBIRD_API_TOKEN="${NETBIRD_API_TOKEN:-}"
export NETBIRD_SETUP_KEY="${NETBIRD_SETUP_KEY:-}"
export NETBIRD_REMNAWAVE_SETUP_KEY="${NETBIRD_REMNAWAVE_SETUP_KEY:-}"
if [ -n "$input_email" ]; then
NETBIRD_LETSENCRYPT_EMAIL="$input_email"
fi
if [ -n "${NETBIRD_LETSENCRYPT_EMAIL:-}" ]; then
extra+=(-e "netbird_letsencrypt_email=${NETBIRD_LETSENCRYPT_EMAIL}")
fi
;;
opnsense)
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/netbird" --format=dotenv-export --silent)"
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/opnsense" --format=dotenv-export --silent)"
# VLESS-ссылки подписок Xray (роль opnsense/xray; ключи — в instances.yml).
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/opnsense-xray" --format=dotenv-export --silent 2>/dev/null || true)"
export NETBIRD_SETUP_KEY="${NETBIRD_SETUP_KEY:-}"
export OPNSENSE_API_KEY="${OPNSENSE_API_KEY:-}"
export OPNSENSE_API_SECRET="${OPNSENSE_API_SECRET:-}"
;;
*-nod-*)
# SECRET_KEY ноды — /services/remnawave (пишет ansible-core-net).
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/remnawave" --format=dotenv-export --silent)"
# Стартовый пароль VPS — /VPS/PASS_<MACHINE_UPPER>.
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/VPS" --format=dotenv-export --silent)"
# CLOUDFLARE_API уже из /ci-cd выше (только A-запись, без DNS-01).
export REMNANODE_SECRET_KEY="${REMNANODE_SECRET_KEY:-}"
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/netbird" --format=dotenv-export --silent 2>/dev/null || true)"
export NETBIRD_API_TOKEN="${NETBIRD_API_TOKEN:-}"
export NETBIRD_REMNAWAVE_SETUP_KEY="${NETBIRD_REMNAWAVE_SETUP_KEY:-}"
export CLOUDFLARE_API="${CLOUDFLARE_API:-}"
pass_var="PASS_${machine^^}"
pass_var="${pass_var//-/_}"
vps_pass="${!pass_var:-}"
if [ -z "${REMNANODE_SECRET_KEY}" ]; then
echo "В Infisical (/services/remnawave) нет REMNANODE_SECRET_KEY — сначала прогоните core-net (роль remnawave)." >&2
exit 1
fi
if [ -z "${CLOUDFLARE_API}" ]; then
echo "В Infisical (/ci-cd) нет CLOUDFLARE_API" >&2
exit 1
fi
if [ -z "${vps_pass}" ]; then
echo "В Infisical (/VPS) нет ${pass_var} — нужен для первичного SSH на ${machine}" >&2
exit 1
fi
if ! command -v sshpass >/dev/null 2>&1; then
apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq sshpass >/dev/null
fi
export ANSIBLE_HOST_KEY_CHECKING=False
vps_extra=$(mktemp)
VPS_PASS="$vps_pass" python3 -c 'import json,os; print(json.dumps({"ansible_password": os.environ["VPS_PASS"]}))' >"$vps_extra"
extra+=(-e "@${vps_extra}")
trap 'rm -f "${HOME}/.ssh/id_ed25519" "'"$vps_extra"'"' EXIT
;;
esac
cd "$root"
target_file=$(mktemp)
bash ansible/ci/ansible-target.sh "$machine" "$event" "$before" "$after" "$override_tags" > "$target_file"
mapfile -t target < "$target_file"
rm -f "$target_file"
if [ "${#target[@]}" -eq 0 ]; then
echo "Для ${machine} нет применимых изменений."
exit 0
fi
export ANSIBLE_HOST_KEY_CHECKING=False
cd "$root/ansible"
key="${HOME}/.ssh/id_ed25519"
ansible-playbook "${target[@]}" \
-i inventories/prod/hosts.yml \
--private-key "$key" \
"${extra[@]}"
+1 -4
View File
@@ -1,5 +1,2 @@
---
# Общие глобальные переменные для всей инфраструктуры homelab (окружение prod)
admin_email: vvkarpenok@gmail.com
letsencrypt_email: "{{ admin_email }}"
letsencrypt_email: vvkarpenok@gmail.com
@@ -1 +0,0 @@
netbird_domain: central.myguni.ru
@@ -0,0 +1,5 @@
---
monitoring_dir: /opt/monitoring
grafana_domain: "graf.gunihome.ru"
ntfy_domain: "ntfy.gunihome.ru"
@@ -0,0 +1,2 @@
---
# Remnawave panel + subscription на этой машине (Traefik уже здесь).
@@ -0,0 +1,13 @@
---
ansible_host: 150.241.64.209
ansible_user: root
remnanode_selfsteal_domain: "yali.gunis.top"
# WAN egress панели (core-net): оба провайдера → NODE_PORT
remnanode_panel_egress_ips:
- "213.128.28.107" # провайдер 1 (МТС)
- "185.160.137.140" # провайдер 2
monitoring_scrape_enabled: false
monitoring_node_exporter_public: false
monitoring_node_exporter_listen: "127.0.0.1:9100"
# Docker на этой машине не принимает API 1.41, которым говорит cAdvisor 0.49.
cadvisor_image: ghcr.io/google/cadvisor:v0.60.6
@@ -0,0 +1,4 @@
---
opnsense_host: "192.168.1.1:4433"
opnsense_netbird_management_url: "https://central.gunihome.ru:443"
@@ -0,0 +1,2 @@
---
netbird_domain: central.gunihome.ru
+26 -7
View File
@@ -1,13 +1,32 @@
# Машины. Состав каждой машины — в playbooks/<хост>.yml.
# Scrape node-exporter (:9100) центральным vmagent: все записи ниже,
# кроме monitoring_scrape_exclude_hosts, хостов с monitoring_scrape_enabled: false
# и хостов из vmagent_central_scrape_skip (у них свой vmagent).
# ger-nod-02 отдаёт метрики своим vmagent.
all:
children:
home:
hosts: {}
vps:
hosts:
core-net:
ansible_host: 192.168.1.104
ansible_user: root
core-secrets:
ansible_host: 192.168.1.102
ansible_user: root
core-mon:
ansible_host: 192.168.1.108
ansible_user: root
core-git:
ansible_host: 192.168.1.105
ansible_user: root
rus-central:
ansible_host: 45.154.185.208
ansible_user: root
ansible_password: fP9vB6zP4nbS
netbird:
ger-nod-02:
ansible_host: 150.241.64.209
ansible_user: root
opnsense:
ansible_host: 192.168.1.1
ansible_connection: local
children:
exit_nodes:
hosts:
rus-central:
ger-nod-02:
+10
View File
@@ -0,0 +1,10 @@
---
# Playbook for core-git (Gitea + Postgres + Actions Runner, cAdvisor)
- name: Развертывание Gitea на core-git
hosts: core-git
become: true
roles:
- role: core-git/gitea
tags: [gitea]
- role: core-git/cadvisor
tags: [cadvisor]
+23
View File
@@ -0,0 +1,23 @@
---
# Playbook for core-mon (Monitoring stack: VictoriaMetrics, vmalert, Alertmanager, Grafana, Ntfy)
- name: Развертывание стека мониторинга на core-mon
hosts: core-mon
roles:
- role: core-mon/monitoring
tags: [monitoring]
post_tasks:
- name: Зарегистрировать Grafana в Agent Vault
ansible.builtin.include_role:
name: agent_vault_service
vars:
agent_vault_service_name: grafana
agent_vault_service_description: >-
Grafana (graf.gunihome.ru): чтение метрик VictoriaMetrics через
datasource proxy/ds query, дашбордов и алертов. Read-only доступ (Viewer).
agent_vault_service_host: "graf.gunihome.ru:443"
agent_vault_service_paths: ["/api"]
agent_vault_service_methods: [GET, POST]
agent_vault_service_credential_type: bearer
agent_vault_secret_path: /services/grafana
agent_vault_secret_key: GRAFANA_API_TOKEN
tags: [agent_vault, monitoring]
+15
View File
@@ -0,0 +1,15 @@
---
- name: CT 902, входной узел
hosts: core-net
become: true
roles:
- role: core-net/traefik
tags: [traefik]
- role: core-net/remnawave
tags: [remnawave]
- role: core-net/authentik
tags: [authentik]
- role: core-net/vmagent
tags: [vmagent]
- role: core-net/netbird
tags: [netbird]
+30
View File
@@ -0,0 +1,30 @@
---
- name: CT 901, секреты
hosts: core-secrets
become: true
roles:
- role: core-secrets/infisical
tags: [infisical]
- role: core-secrets/vaultwarden
tags: [vaultwarden]
- role: core-secrets/cadvisor
tags: [cadvisor]
post_tasks:
- name: Зарегистрировать Gitea в Agent Vault
ansible.builtin.include_role:
name: agent_vault_service
apply:
tags: [agent_vault, gitea]
vars:
agent_vault_service_name: gitea
agent_vault_service_description: >-
Gitea (gitea.gunihome.ru): чтение репозиториев, коммитов и логов
CI/Actions. Read-only доступ (GET) через токен.
agent_vault_service_host: "gitea.gunihome.ru:443"
agent_vault_service_paths: ["/api"]
agent_vault_service_methods: [GET]
agent_vault_service_credential_type: bearer
agent_vault_service_header_prefix: token
agent_vault_secret_path: /ci-cd
agent_vault_secret_key: TF_STATE_TOKEN
tags: [agent_vault, gitea]
+11
View File
@@ -0,0 +1,11 @@
---
- name: Ger-nod-02, Remnawave Node + SelfSteal
hosts: ger-nod-02
gather_facts: false
roles:
- role: netbird_exit_node
tags: [netbird]
- role: remnanode
tags: [remnanode]
- role: vmagent
tags: [vmagent]
+1 -1
View File
@@ -1,6 +1,6 @@
---
- name: Подготовить машину
hosts: all
hosts: all:!opnsense
gather_facts: false
roles:
- role: host
-10
View File
@@ -1,10 +0,0 @@
---
- name: Установить панель NetBird
hosts: netbird
gather_facts: false
roles:
- role: netbird
tags:
- netbird
- vpn
- config
+27
View File
@@ -0,0 +1,27 @@
---
- name: Маршрутизатор OPNsense
hosts: opnsense
gather_facts: false
roles:
- role: opnsense/netbird
tags: [netbird]
- role: opnsense/xray
tags: [xray]
post_tasks:
- name: Зарегистрировать OPNsense в Agent Vault
ansible.builtin.include_role:
name: agent_vault_service
vars:
agent_vault_service_name: opnsense
agent_vault_service_description: >-
Маршрутизатор OPNsense (opnsense.gunihome.ru): статус системы, интерфейсы,
правила фаервола, маршруты, NetBird и Xray. Read-only доступ (GET) через
Basic Auth (OPNSENSE_API_KEY / OPNSENSE_API_SECRET).
agent_vault_service_host: "opnsense.gunihome.ru:443"
agent_vault_service_paths: ["/api"]
agent_vault_service_methods: [GET]
agent_vault_service_credential_type: basic
agent_vault_secret_path: /services/opnsense
agent_vault_secret_username_key: OPNSENSE_API_KEY
agent_vault_secret_password_key: OPNSENSE_API_SECRET
tags: [agent_vault, netbird, xray]
+9
View File
@@ -0,0 +1,9 @@
---
- name: VPS rus-central, NetBird
hosts: rus-central
gather_facts: false
roles:
- role: rus-central/netbird
tags: [netbird]
- role: rus-central/cadvisor
tags: [cadvisor]
+7 -1
View File
@@ -1,3 +1,9 @@
---
- ansible.builtin.import_playbook: host.yml
- ansible.builtin.import_playbook: netbird.yml
- ansible.builtin.import_playbook: core-net.yml
- ansible.builtin.import_playbook: core-secrets.yml
- ansible.builtin.import_playbook: core-mon.yml
- ansible.builtin.import_playbook: core-git.yml
- ansible.builtin.import_playbook: rus-central.yml
- ansible.builtin.import_playbook: ger-nod-02.yml
- ansible.builtin.import_playbook: opnsense.yml
@@ -0,0 +1,33 @@
---
# Регистрация сервиса продукта в Access Bundle Agent Vault.
# Роль ничего не знает о продукте: всё приходит переменными от вызывающей роли.
agent_vault_project_name: homelab-agents
agent_vault_bundle_name: homelab-ops
# Токен и адрес берутся из окружения пайплайна (deploy-machine.sh: INFISICAL_TOKEN).
agent_vault_domain: "{{ lookup('env', 'INFISICAL_DOMAIN') }}"
agent_vault_access_token: "{{ lookup('env', 'INFISICAL_TOKEN') }}"
agent_vault_service_name: ""
agent_vault_service_description: ""
# Хост в виде host:port, как его видит агент через прокси (публичное имя, не 127.0.0.1).
agent_vault_service_host: ""
# Пустые списки означают «любые методы» и «любые пути».
agent_vault_service_methods: [GET]
agent_vault_service_paths: []
# Как прокси подставляет креденшл: bearer (по умолчанию) или basic.
# Для bearer — «Authorization: Bearer <токен>» (или header_name / header_prefix).
# Для basic — «Authorization: Basic <base64(username:password)>» по паре ключей.
agent_vault_service_credential_type: bearer
agent_vault_service_header_name: ""
agent_vault_service_header_prefix: ""
# Откуда брать креденшл: путь и ключ(и) секрета в проекте infra.
agent_vault_secret_project_id: "{{ lookup('env', 'INFISICAL_PROJECT_ID') }}"
agent_vault_secret_env: prod
agent_vault_secret_path: ""
agent_vault_secret_key: ""
agent_vault_secret_username_key: ""
agent_vault_secret_password_key: ""
@@ -0,0 +1,272 @@
---
# Идемпотентная регистрация сервиса в Access Bundle Agent Vault.
# Сервис ищется по имени в бандле: нет — создаётся, есть — обновляется.
# Креденшл читается из Infisical и перезаписывается при каждом прогоне,
# поэтому токен не проходит через переменные Ansible.
#
# Использование:
# - ansible.builtin.include_role:
# name: agent_vault_service
# vars:
# agent_vault_service_name: remnawave-panel
# agent_vault_service_host: "rw.gunihome.ru:443"
# agent_vault_service_paths: ["/api"]
# agent_vault_service_methods: [GET, POST]
# agent_vault_secret_path: /services/remnawave
# agent_vault_secret_key: REMNAWAVE_API_TOKEN
- name: Проверить параметры сервиса Agent Vault
ansible.builtin.assert:
that:
- agent_vault_service_name | default('') | length > 0
- agent_vault_service_host | default('') | length > 0
- agent_vault_secret_path | default('') | length > 0
- agent_vault_service_credential_type in ['bearer', 'basic']
- >-
(agent_vault_service_credential_type == 'bearer' and agent_vault_secret_key | default('') | length > 0)
or
(agent_vault_service_credential_type == 'basic'
and agent_vault_secret_username_key | default('') | length > 0
and agent_vault_secret_password_key | default('') | length > 0)
- agent_vault_domain | default('') | length > 0
- agent_vault_access_token | default('') | length > 0
fail_msg: >-
agent_vault_service: нужны agent_vault_service_name, agent_vault_service_host,
agent_vault_secret_path, ключ(и) секрета (agent_vault_secret_key для bearer или
agent_vault_secret_username_key/agent_vault_secret_password_key для basic),
а также INFISICAL_DOMAIN и INFISICAL_TOKEN в окружении.
quiet: true
no_log: true
- name: Определить список ключей секретов для чтения
ansible.builtin.set_fact:
agent_vault_secret_keys_to_read: >-
{{ [agent_vault_secret_key]
if agent_vault_service_credential_type == 'bearer'
else [agent_vault_secret_username_key, agent_vault_secret_password_key] }}
no_log: true
- name: Прочитать секреты сервиса из Infisical
ansible.builtin.shell: |
set -euo pipefail
infisical secrets get "${SECRET_KEY}" \
--domain="${INFISICAL_DOMAIN}" \
--token="${INFISICAL_TOKEN}" \
--env="${SECRET_ENV}" \
--projectId="${INFISICAL_PROJECT_ID}" \
--path="${SECRET_PATH}" \
--plain
args:
executable: /bin/bash
environment:
INFISICAL_DOMAIN: "{{ agent_vault_domain }}"
INFISICAL_TOKEN: "{{ agent_vault_access_token }}"
INFISICAL_PROJECT_ID: "{{ agent_vault_secret_project_id }}"
SECRET_KEY: "{{ item }}"
SECRET_PATH: "{{ agent_vault_secret_path }}"
SECRET_ENV: "{{ agent_vault_secret_env }}"
loop: "{{ agent_vault_secret_keys_to_read }}"
register: agent_vault_secrets_raw
changed_when: false
no_log: true
delegate_to: localhost
become: false
- name: Проверить, что прочитанные секреты не пустые
ansible.builtin.assert:
that:
- >-
agent_vault_secrets_raw.results | map(attribute='stdout') | map('trim')
| select('equalto', '') | list | length == 0
fail_msg: >-
В Infisical отсутствует один из ключей ({{ agent_vault_secret_keys_to_read | join(', ') }})
по пути {{ agent_vault_secret_path }} (env {{ agent_vault_secret_env }}),
либо у идентичности нет прав на чтение.
quiet: true
no_log: true
- name: Получить список проектов Infisical
ansible.builtin.uri:
url: "{{ agent_vault_domain }}/v1/projects"
headers:
Authorization: "Bearer {{ agent_vault_access_token }}"
status_code: 200
use_proxy: false
register: agent_vault_projects
changed_when: false
delegate_to: localhost
become: false
- name: Найти Agent Vault-проект по имени
ansible.builtin.set_fact:
agent_vault_project_id: >-
{{ agent_vault_projects.json.projects | default([])
| selectattr('name', 'equalto', agent_vault_project_name)
| map(attribute='id') | list | first | default('', true) }}
- name: Проверить, что проект найден
ansible.builtin.assert:
that:
- agent_vault_project_id | length > 0
fail_msg: >-
Проект {{ agent_vault_project_name }} не найден, либо идентичность пайплайна
не добавлена в него с ролью Admin (Access Control → Machine Identities).
quiet: true
- name: Получить Access Bundles проекта
ansible.builtin.uri:
url: "{{ agent_vault_domain }}/v1/agent-vault/access-bundles?projectId={{ agent_vault_project_id }}&limit=100"
headers:
Authorization: "Bearer {{ agent_vault_access_token }}"
status_code: 200
use_proxy: false
register: agent_vault_bundles
changed_when: false
delegate_to: localhost
become: false
- name: Найти Access Bundle по имени
ansible.builtin.set_fact:
agent_vault_bundle_id: >-
{{ agent_vault_bundles.json.accessBundles | default([])
| selectattr('name', 'equalto', agent_vault_bundle_name)
| map(attribute='id') | list | first | default('', true) }}
- name: Проверить, что бандл найден
ansible.builtin.assert:
that:
- agent_vault_bundle_id | length > 0
fail_msg: >-
Access Bundle {{ agent_vault_bundle_name }} не найден в проекте
{{ agent_vault_project_name }}.
quiet: true
- name: Прочитать сервисы бандла
ansible.builtin.uri:
url: "{{ agent_vault_domain }}/v1/agent-vault/access-bundles/{{ agent_vault_bundle_id }}"
headers:
Authorization: "Bearer {{ agent_vault_access_token }}"
status_code: 200
use_proxy: false
register: agent_vault_bundle
changed_when: false
delegate_to: localhost
become: false
- name: Найти сервис по имени в бандле
ansible.builtin.set_fact:
agent_vault_service_id: >-
{{ agent_vault_bundle.json.accessBundle.services | default([])
| selectattr('name', 'equalto', agent_vault_service_name)
| map(attribute='id') | list | first | default('', true) }}
- name: Собрать креденшл сервиса
ansible.builtin.set_fact:
agent_vault_service_credential: >-
{{ ({'type': 'bearer', 'value': (agent_vault_secrets_raw.results[0].stdout | trim)}
| combine({'headerName': agent_vault_service_header_name}
if agent_vault_service_header_name | length > 0 else {})
| combine({'headerPrefix': agent_vault_service_header_prefix}
if agent_vault_service_header_prefix | length > 0 else {}))
if agent_vault_service_credential_type == 'bearer'
else {'type': 'basic',
'username': (agent_vault_secrets_raw.results[0].stdout | trim),
'password': (agent_vault_secrets_raw.results[1].stdout | trim)} }}
no_log: true
- name: Собрать тело сервиса
ansible.builtin.set_fact:
agent_vault_service_body:
type: http
name: "{{ agent_vault_service_name }}"
hostPattern: "{{ agent_vault_service_host }}"
allowedMethods: "{{ agent_vault_service_methods | length | ternary(agent_vault_service_methods, none) }}"
allowedPathPrefixes: "{{ agent_vault_service_paths | length | ternary(agent_vault_service_paths, none) }}"
description: "{{ agent_vault_service_description | length | ternary(agent_vault_service_description, none) }}"
credential: "{{ agent_vault_service_credential }}"
no_log: true
- name: Создать сервис в бандле
ansible.builtin.uri:
url: "{{ agent_vault_domain }}/v1/agent-vault/access-bundles/{{ agent_vault_bundle_id }}/services"
method: POST
body_format: json
body: "{{ agent_vault_service_body }}"
headers:
Authorization: "Bearer {{ agent_vault_access_token }}"
status_code: [200, 201]
use_proxy: false
register: agent_vault_service_created
no_log: true
changed_when: true
delegate_to: localhost
become: false
when: agent_vault_service_id | length == 0
- name: Обновить сервис в бандле
ansible.builtin.uri:
url: "{{ agent_vault_domain }}/v1/agent-vault/access-bundles/{{ agent_vault_bundle_id }}/services/{{ agent_vault_service_id }}"
method: PATCH
body_format: json
body: "{{ agent_vault_service_body }}"
headers:
Authorization: "Bearer {{ agent_vault_access_token }}"
status_code: [200, 201]
use_proxy: false
register: agent_vault_service_updated
no_log: true
changed_when: true
failed_when: false
delegate_to: localhost
become: false
when: agent_vault_service_id | length > 0
# Если PATCH не принят (например, сервис остался от прежней схемы),
# пересоздаём его: прокси применит изменение на следующем poll.
- name: Сбросить признак пересоздания
ansible.builtin.set_fact:
agent_vault_service_recreated: false
- name: Пересоздать сервис, если PATCH отклонён
when:
- agent_vault_service_id | length > 0
- agent_vault_service_updated.status | default(0) not in [200, 201]
block:
- name: Удалить старый сервис
ansible.builtin.uri:
url: "{{ agent_vault_domain }}/v1/agent-vault/access-bundles/{{ agent_vault_bundle_id }}/services/{{ agent_vault_service_id }}"
method: DELETE
headers:
Authorization: "Bearer {{ agent_vault_access_token }}"
status_code: [200, 204]
use_proxy: false
changed_when: true
delegate_to: localhost
become: false
- name: Создать сервис заново
ansible.builtin.uri:
url: "{{ agent_vault_domain }}/v1/agent-vault/access-bundles/{{ agent_vault_bundle_id }}/services"
method: POST
body_format: json
body: "{{ agent_vault_service_body }}"
headers:
Authorization: "Bearer {{ agent_vault_access_token }}"
status_code: [200, 201]
use_proxy: false
no_log: true
changed_when: true
delegate_to: localhost
become: false
- name: Отметить пересоздание
ansible.builtin.set_fact:
agent_vault_service_recreated: true
- name: Сообщить результат
ansible.builtin.debug:
msg: >-
Agent Vault: сервис {{ agent_vault_service_name }} в бандле
{{ agent_vault_bundle_name }}
{{ 'пересоздан' if agent_vault_service_recreated | default(false)
else ('обновлён' if agent_vault_service_id | length > 0 else 'создан') }}.
+4
View File
@@ -0,0 +1,4 @@
---
cadvisor_dir: /opt/cadvisor
cadvisor_image: gcr.io/cadvisor/cadvisor:v0.49.2
cadvisor_port: 9101
+40
View File
@@ -0,0 +1,40 @@
---
- name: Каталог cAdvisor
ansible.builtin.file:
path: "{{ cadvisor_dir }}"
state: directory
owner: root
group: root
mode: "0755"
- name: Compose cAdvisor
ansible.builtin.template:
src: compose.yaml.j2
dest: "{{ cadvisor_dir }}/compose.yaml"
owner: root
group: root
mode: "0644"
- name: Разрешить порт cAdvisor в firewall
ansible.builtin.command: ufw allow {{ cadvisor_port }}/tcp
register: ufw_cadvisor
changed_when: "'added' in (ufw_cadvisor.stdout | lower)"
when: ansible_virtualization_type | default('') != 'lxc'
- name: Запустить cAdvisor
ansible.builtin.command: docker compose -f {{ cadvisor_dir }}/compose.yaml up -d --remove-orphans
register: cadvisor_up
changed_when: >-
'Started' in cadvisor_up.stderr or
'Created' in cadvisor_up.stderr or
'Recreated' in cadvisor_up.stderr or
'Pulled' in cadvisor_up.stderr
- name: Дождаться cAdvisor
ansible.builtin.uri:
url: "http://127.0.0.1:{{ cadvisor_port }}/healthz"
status_code: 200
register: cadvisor_health
retries: 15
delay: 2
until: cadvisor_health.status == 200
@@ -0,0 +1,26 @@
name: cadvisor
services:
cadvisor:
image: {{ cadvisor_image }}
container_name: cadvisor
restart: unless-stopped
privileged: true
command:
- --listen_ip=0.0.0.0
- --port={{ cadvisor_port }}
- --docker_only=true
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker:/var/lib/docker:ro
- /dev/disk:/dev/disk:ro
ports:
- "{{ cadvisor_port }}:{{ cadvisor_port }}"
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:{{ cadvisor_port }}/healthz"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
@@ -0,0 +1,4 @@
---
- name: cAdvisor core-git
ansible.builtin.include_role:
name: cadvisor
@@ -0,0 +1,26 @@
---
gitea_dir: /opt/gitea
gitea_http_port: 3000
gitea_ssh_port: 222
gitea_image: "docker.gitea.com/gitea:28.3.0"
gitea_postgres_image: "postgres:14"
gitea_runner_image: "docker.io/gitea/runner:5-dind"
gitea_domain: "gitea.gunihome.ru"
gitea_root_url: "https://gitea.gunihome.ru"
# Стабильное имя для clone SSH (Unbound), не LAN IP CT.
gitea_ssh_domain: "gitea.internal"
gitea_postgres_user: "{{ lookup('env', 'GITEA_POSTGRES_USER', default='gitea') }}"
gitea_postgres_db: "{{ lookup('env', 'GITEA_POSTGRES_DB', default='gitea') }}"
gitea_postgres_password: "{{ lookup('env', 'GITEA_POSTGRES_PASSWORD') }}"
# Пустой стек до ручной миграции не поднимаем: compose пишется при секретах, up — когда есть PG_VERSION.
gitea_bootstrap_empty: false
gitea_runner_name: homelab
gitea_runner_labels: "homelab:docker://docker.gitea.com/runner-images:ubuntu-latest"
gitea_runner_instance_url: "{{ gitea_root_url }}"
gitea_runner_registration_token: "{{ lookup('env', 'GITEA_RUNNER_REGISTRATION_TOKEN', default='') }}"
# Включается, если есть токен регистрации или уже лежит runner-data/.runner (после миграции).
gitea_runner_enabled: false
@@ -0,0 +1,87 @@
---
- name: Есть ли данные Postgres (после миграции)
ansible.builtin.stat:
path: "{{ gitea_dir }}/postgres/PG_VERSION"
register: gitea_postgres_data
- name: Есть ли уже регистрация runner
ansible.builtin.stat:
path: "{{ gitea_dir }}/runner-data/.runner"
register: gitea_runner_file
- name: Секреты и данные
ansible.builtin.set_fact:
gitea_secrets_ready: "{{ (gitea_postgres_password | default('') | length > 0) }}"
gitea_data_ready: "{{ gitea_postgres_data.stat.exists | default(false) }}"
- name: Когда поднимать compose
ansible.builtin.set_fact:
gitea_stack_ready: "{{ gitea_secrets_ready and (gitea_data_ready or (gitea_bootstrap_empty | bool)) }}"
- name: Без пароля — только каталоги
ansible.builtin.debug:
msg: "GITEA_POSTGRES_PASSWORD пуст — compose не пишем. Нужен Infisical /services/gitea."
when: not gitea_secrets_ready
- name: Секреты есть, данных ещё нет — ждём ручную миграцию
ansible.builtin.debug:
msg: "Секреты на месте, PG_VERSION нет — пишем compose, up не делаем (миграция руками)."
when: gitea_secrets_ready and not gitea_stack_ready
- name: Пароль обязателен при наличии данных БД
ansible.builtin.assert:
that:
- gitea_postgres_password | length > 0
fail_msg: "Есть данные Postgres в {{ gitea_dir }}/postgres, но GITEA_POSTGRES_PASSWORD пуст."
when: gitea_data_ready
- name: Включить runner при токене или существующем .runner
ansible.builtin.set_fact:
gitea_runner_enabled: "{{ gitea_stack_ready and ((gitea_runner_registration_token | default('') | length > 0) or (gitea_runner_file.stat.exists | default(false))) }}"
- name: Создать каталоги Gitea
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
loop:
- { path: "{{ gitea_dir }}", owner: "root", group: "root", mode: "0755" }
- { path: "{{ gitea_dir }}/gitea", owner: "root", group: "root", mode: "0755" }
- { path: "{{ gitea_dir }}/postgres", owner: "999", group: "999", mode: "0700" }
- { path: "{{ gitea_dir }}/runner-data", owner: "root", group: "root", mode: "0700" }
- { path: "{{ gitea_dir }}/images", owner: "root", group: "root", mode: "0700" }
- name: Установить compose.yaml для Gitea
ansible.builtin.template:
src: compose.yaml.j2
dest: "{{ gitea_dir }}/compose.yaml"
owner: root
group: root
mode: "0600"
no_log: true
when: gitea_secrets_ready
- name: Запустить Gitea
ansible.builtin.command: docker compose -f {{ gitea_dir }}/compose.yaml up -d --remove-orphans
register: gitea_compose_up
changed_when: >-
'Started' in gitea_compose_up.stderr or
'Created' in gitea_compose_up.stderr or
'Recreated' in gitea_compose_up.stderr or
'Pulled' in gitea_compose_up.stderr
when: gitea_stack_ready
- name: Скрипт архива образа homelab-ansible
ansible.builtin.template:
src: ensure-runner-image.sh.j2
dest: "{{ gitea_dir }}/ensure-runner-image.sh"
owner: root
group: root
mode: "0700"
when: gitea_runner_enabled
- name: Образ homelab-ansible в раннере или в архиве
ansible.builtin.command: "{{ gitea_dir }}/ensure-runner-image.sh"
when: gitea_runner_enabled and gitea_stack_ready
@@ -0,0 +1,77 @@
name: gitea
networks:
gitea:
external: false
{% if gitea_runner_enabled %}
volumes:
runner-docker:
{% endif %}
services:
server:
image: {{ gitea_image }}
container_name: gitea
environment:
GITEA__database__DB_TYPE: postgres
GITEA__database__HOST: db:5432
GITEA__database__NAME: {{ gitea_postgres_db | to_json }}
GITEA__database__USER: {{ gitea_postgres_user | to_json }}
GITEA__database__PASSWD: {{ gitea_postgres_password | to_json }}
GITEA__server__ROOT_URL: {{ gitea_root_url | to_json }}
GITEA__server__DOMAIN: {{ gitea_domain | to_json }}
GITEA__server__SSH_DOMAIN: {{ gitea_ssh_domain | to_json }}
GITEA__server__SSH_PORT: "{{ gitea_ssh_port }}"
GITEA__service__DISABLE_REGISTRATION: "true"
restart: always
networks:
- gitea
volumes:
- {{ gitea_dir }}/gitea:/data
ports:
- "{{ gitea_http_port }}:3000"
- "{{ gitea_ssh_port }}:22"
depends_on:
db:
condition: service_healthy
db:
image: {{ gitea_postgres_image }}
container_name: gitea-db
restart: always
environment:
POSTGRES_USER: {{ gitea_postgres_user | to_json }}
POSTGRES_PASSWORD: {{ gitea_postgres_password | to_json }}
POSTGRES_DB: {{ gitea_postgres_db | to_json }}
networks:
- gitea
volumes:
- {{ gitea_dir }}/postgres:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U {{ gitea_postgres_user }} -d {{ gitea_postgres_db }}"]
interval: 5s
timeout: 5s
retries: 10
start_period: 20s
{% if gitea_runner_enabled %}
runner:
image: {{ gitea_runner_image }}
container_name: gitea-runner
restart: always
privileged: true
environment:
GITEA_INSTANCE_URL: {{ gitea_runner_instance_url | to_json }}
GITEA_RUNNER_NAME: {{ gitea_runner_name | to_json }}
GITEA_RUNNER_LABELS: {{ gitea_runner_labels | to_json }}
{% if gitea_runner_registration_token | length > 0 %}
GITEA_RUNNER_REGISTRATION_TOKEN: {{ gitea_runner_registration_token | to_json }}
{% endif %}
networks:
- gitea
volumes:
- {{ gitea_dir }}/runner-data:/data
- {{ gitea_dir }}/images:/images:ro
- runner-docker:/var/lib/docker
{% endif %}
@@ -0,0 +1,28 @@
#!/bin/bash
# Образ homelab-ansible есть только на этой машине. Архив лежит на диске CT,
# не внутри volume DinD: очистка volume его не стирает.
set -euo pipefail
archive="{{ gitea_dir }}/images/homelab-ansible.tar"
container_archive="/images/homelab-ansible.tar"
if docker exec gitea-runner docker image inspect homelab-ansible:latest >/dev/null 2>&1; then
if [ ! -s "$archive" ]; then
mkdir -p "{{ gitea_dir }}/images"
docker exec gitea-runner docker save homelab-ansible:latest > "$archive"
chmod 600 "$archive"
echo "saved ${archive}"
else
echo "present"
fi
exit 0
fi
if [ -s "$archive" ]; then
docker exec gitea-runner docker load -i "$container_archive"
echo "loaded"
exit 0
fi
echo "Образ homelab-ansible:latest не найден ни в раннере, ни в ${archive}" >&2
exit 1
@@ -0,0 +1,43 @@
---
monitoring_dir: /opt/monitoring
victoriametrics_retention: "30d"
# Цели node-exporter: все хосты из inventory, кроме исключений.
# Отключить scrape на хосте: host_vars monitoring_scrape_enabled: false
# Другой адрес/порт: monitoring_scrape_address, monitoring_node_exporter_port
monitoring_scrape_exclude_hosts:
- opnsense
monitoring_node_exporter_port: 9100
victoriametrics_image: victoriametrics/victoria-metrics:v1.153.0
vmalert_image: victoriametrics/vmalert:v1.153.0
vmagent_image: victoriametrics/vmagent:v1.153.0
# Свой vmagent уже пишет node-exporter этих хостов. Повторный scrape даст двойные сэмплы.
vmagent_central_scrape_skip:
- core-mon
- core-net
cadvisor_image: gcr.io/cadvisor/cadvisor:v0.49.2
xray_checker_image: kutovoys/xray-checker:v1.3.1
xray_checker_subscription_url: "{{ lookup('env', 'XRAY_CHECKER_SUBSCRIPTION_URL', default='') }}"
opnsense_exporter_image: "python:3.12-alpine"
opnsense_api_url: "https://192.168.1.1:4433"
opnsense_api_key: "{{ lookup('env', 'OPNSENSE_API_KEY', default='') }}"
opnsense_api_secret: "{{ lookup('env', 'OPNSENSE_API_SECRET', default='') }}"
opnsense_exporter_enabled: "{{ (opnsense_api_key | length > 0) and (opnsense_api_secret | length > 0) }}"
vmagent_cluster: homelab
# cAdvisor этих хостов слушает :9101. core-mon, core-net и ger-nod-02 пишут его своим агентом.
monitoring_cadvisor_port: 9101
monitoring_cadvisor_scrape_hosts:
- core-secrets
- rus-central
- core-git
grafana_admin_user: "{{ lookup('ansible.builtin.env', 'ADMIN_USER', default='karpenok') }}"
grafana_admin_password: "{{ lookup('ansible.builtin.env', 'ADMIN_PASSWORD', default='') }}"
grafana_admin_email: "{{ lookup('ansible.builtin.env', 'MAIL_ADMIN_USER', default=grafana_admin_user ~ '@gunihome.ru') }}"
grafana_root_url: "https://graf.gunihome.ru"
ntfy_base_url: "https://ntfy.gunihome.ru"
ntfy_default_topic: "homelab-alerts"
ntfy_admin_user: "{{ grafana_admin_user }}"
ntfy_admin_password: "{{ grafana_admin_password }}"
@@ -0,0 +1,329 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 1,
"id": null,
"links": [],
"panels": [
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": {
"mappings": [
{ "options": { "0": { "color": "red", "index": 1, "text": "Offline" }, "1": { "color": "green", "index": 0, "text": "Online" } }, "type": "value" }
],
"thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "green", "value": 1 }] }
},
"overrides": []
},
"gridPos": { "h": 4, "w": 4, "x": 0, "y": 0 },
"id": 1,
"options": { "colorMode": "background", "graphMode": "none", "justifyMode": "center", "orientation": "auto", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "auto" },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_gateway_status{gateway=\"NORCOM_DHCP\"}", "refId": "A" }],
"title": "NorCom (Primary)",
"type": "stat"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": {
"mappings": [
{ "options": { "0": { "color": "red", "index": 1, "text": "Offline" }, "1": { "color": "green", "index": 0, "text": "Online" } }, "type": "value" }
],
"thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "green", "value": 1 }] }
},
"overrides": []
},
"gridPos": { "h": 4, "w": 4, "x": 4, "y": 0 },
"id": 2,
"options": { "colorMode": "background", "graphMode": "none", "justifyMode": "center", "orientation": "auto", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "auto" },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_gateway_status{gateway=\"WAN1\"}", "refId": "A" }],
"title": "MTC (WAN1)",
"type": "stat"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": {
"mappings": [
{ "options": { "0": { "color": "blue", "index": 1, "text": "Offline (sched)" }, "1": { "color": "green", "index": 0, "text": "Online" } }, "type": "value" }
],
"thresholds": { "mode": "absolute", "steps": [{ "color": "blue", "value": null }, { "color": "green", "value": 1 }] }
},
"overrides": []
},
"gridPos": { "h": 4, "w": 4, "x": 8, "y": 0 },
"id": 3,
"options": { "colorMode": "background", "graphMode": "none", "justifyMode": "center", "orientation": "auto", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "auto" },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_gateway_status{gateway=\"WAN_0\"}", "refId": "A" }],
"title": "Iterika (WAN_0)",
"type": "stat"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": {
"color": { "mode": "fixed", "fixedColor": "super-light-blue" }
},
"overrides": []
},
"gridPos": { "h": 4, "w": 4, "x": 12, "y": 0 },
"id": 4,
"options": { "colorMode": "value", "graphMode": "none", "justifyMode": "center", "orientation": "auto", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "name" },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_gateway_default == 1", "legendFormat": "{{gateway}} ({{descr}})", "refId": "A" }],
"title": "Active Default GW",
"type": "stat"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": {
"unit": "short",
"thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "orange", "value": 50000 }, { "color": "red", "value": 200000 }] }
},
"overrides": []
},
"gridPos": { "h": 4, "w": 4, "x": 16, "y": 0 },
"id": 5,
"options": { "colorMode": "value", "graphMode": "area", "justifyMode": "center", "orientation": "auto", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "auto" },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_pf_states_current", "refId": "A" }],
"title": "pf Active States",
"type": "stat"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": {
"unit": "percent",
"thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "orange", "value": 75 }, { "color": "red", "value": 90 }] }
},
"overrides": []
},
"gridPos": { "h": 4, "w": 4, "x": 20, "y": 0 },
"id": 6,
"options": { "colorMode": "value", "graphMode": "area", "justifyMode": "center", "orientation": "auto", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "auto" },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "(opnsense_memory_used_bytes / opnsense_memory_total_bytes) * 100", "refId": "A" }],
"title": "RAM Usage",
"type": "stat"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": {
"mappings": [
{ "options": { "0": { "color": "red", "index": 1, "text": "Offline" }, "1": { "color": "green", "index": 0, "text": "Online" } }, "type": "value" }
]
},
"overrides": [
{
"matcher": { "id": "byName", "options": "WAN_0 (Iterika)" },
"properties": [
{
"id": "mappings",
"value": [
{ "options": { "0": { "color": "blue", "index": 1, "text": "Offline (sched)" }, "1": { "color": "green", "index": 0, "text": "Online" } }, "type": "value" }
]
}
]
}
]
},
"gridPos": { "h": 5, "w": 12, "x": 0, "y": 4 },
"id": 7,
"options": { "alignValue": "left", "legend": { "displayMode": "list", "placement": "bottom", "showLegend": true }, "mergeValues": true, "rowHeight": 0.8, "showValue": "auto" },
"targets": [
{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_gateway_status{gateway=~\"NORCOM_DHCP|WAN1|WAN_0\"}", "legendFormat": "{{gateway}} ({{descr}})", "refId": "A" }
],
"title": "Gateway Availability (dpinger)",
"type": "state-timeline"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": {
"mappings": [
{ "options": { "0": { "color": "semi-dark-purple", "index": 1, "text": "Standby" }, "1": { "color": "green", "index": 0, "text": "Active" } }, "type": "value" }
]
},
"overrides": []
},
"gridPos": { "h": 5, "w": 12, "x": 12, "y": 4 },
"id": 18,
"options": { "alignValue": "left", "legend": { "displayMode": "list", "placement": "bottom", "showLegend": true }, "mergeValues": true, "rowHeight": 0.8, "showValue": "auto" },
"targets": [
{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_gateway_default{gateway=~\"NORCOM_DHCP|WAN1|WAN_0\"}", "legendFormat": "{{gateway}} ({{descr}})", "refId": "A" }
],
"title": "Active Default Route (Failover)",
"type": "state-timeline"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": { "unit": "ms", "custom": { "drawStyle": "line", "lineWidth": 2, "fillOpacity": 10 } },
"overrides": []
},
"gridPos": { "h": 7, "w": 12, "x": 0, "y": 9 },
"id": 8,
"options": { "legend": { "displayMode": "table", "placement": "bottom", "showLegend": true, "calcs": ["mean", "max", "lastNotNull"] }, "tooltip": { "mode": "multi" } },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_gateway_delay_seconds{gateway=~\"NORCOM_DHCP|WAN1|WAN_0\"} * 1000", "legendFormat": "{{gateway}} ({{descr}} -> {{monitor}})", "refId": "A" }],
"title": "Gateway Latency (RTT, dpinger)",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": { "unit": "percent", "min": 0, "max": 100, "custom": { "drawStyle": "line", "lineWidth": 2, "fillOpacity": 15 } },
"overrides": []
},
"gridPos": { "h": 7, "w": 12, "x": 12, "y": 9 },
"id": 9,
"options": { "legend": { "displayMode": "table", "placement": "bottom", "showLegend": true, "calcs": ["mean", "max", "lastNotNull"] }, "tooltip": { "mode": "multi" } },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_gateway_loss_ratio{gateway=~\"NORCOM_DHCP|WAN1|WAN_0\"} * 100", "legendFormat": "{{gateway}} ({{descr}})", "refId": "A" }],
"title": "Gateway Packet Loss (%)",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": { "unit": "bps", "custom": { "drawStyle": "line", "lineWidth": 1.5, "fillOpacity": 15 } },
"overrides": []
},
"gridPos": { "h": 7, "w": 12, "x": 0, "y": 16 },
"id": 10,
"options": { "legend": { "displayMode": "table", "placement": "bottom", "showLegend": true, "calcs": ["mean", "max", "lastNotNull"] }, "tooltip": { "mode": "multi" } },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "rate(opnsense_interface_rx_bytes_total{device=~\"igc0|igc1|igc2|proxytun2socks0|vtnet0\"}[1m]) * 8", "legendFormat": "RX {{descr}} ({{device}})", "refId": "A" }],
"title": "Interface Download (RX)",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": { "unit": "bps", "custom": { "drawStyle": "line", "lineWidth": 1.5, "fillOpacity": 15 } },
"overrides": []
},
"gridPos": { "h": 7, "w": 12, "x": 12, "y": 16 },
"id": 11,
"options": { "legend": { "displayMode": "table", "placement": "bottom", "showLegend": true, "calcs": ["mean", "max", "lastNotNull"] }, "tooltip": { "mode": "multi" } },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "rate(opnsense_interface_tx_bytes_total{device=~\"igc0|igc1|igc2|proxytun2socks0|vtnet0\"}[1m]) * 8", "legendFormat": "TX {{descr}} ({{device}})", "refId": "A" }],
"title": "Interface Upload (TX)",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": { "unit": "pps", "custom": { "drawStyle": "line", "lineWidth": 1.5, "fillOpacity": 10 } },
"overrides": []
},
"gridPos": { "h": 6, "w": 12, "x": 0, "y": 23 },
"id": 12,
"options": { "legend": { "displayMode": "list", "placement": "bottom", "showLegend": true }, "tooltip": { "mode": "multi" } },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "rate(opnsense_interface_rx_errors_total{device=~\"igc0|igc1|igc2|vtnet0\"}[5m]) + rate(opnsense_interface_tx_errors_total{device=~\"igc0|igc1|igc2|vtnet0\"}[5m]) + rate(opnsense_interface_dropped_packets_total{device=~\"igc0|igc1|igc2|vtnet0\"}[5m])", "legendFormat": "{{descr}} ({{device}})", "refId": "A" }],
"title": "Interface Errors & Drops",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": {
"mappings": [
{ "options": { "0": { "color": "red", "index": 1, "text": "Stopped" }, "1": { "color": "green", "index": 0, "text": "Running" } }, "type": "value" }
],
"thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "green", "value": 1 }] }
},
"overrides": []
},
"gridPos": { "h": 6, "w": 12, "x": 12, "y": 23 },
"id": 13,
"options": { "colorMode": "background", "graphMode": "none", "justifyMode": "auto", "orientation": "auto", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "value_and_name" },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_service_running{name=~\"unbound|xray|netbird|dhcpd|pf|node_exporter\"}", "legendFormat": "{{name}}", "refId": "A" }],
"title": "OPNsense Services",
"type": "stat"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": { "unit": "percent", "min": 0, "max": 100, "custom": { "drawStyle": "line", "lineWidth": 2, "fillOpacity": 15 } },
"overrides": []
},
"gridPos": { "h": 6, "w": 8, "x": 0, "y": 29 },
"id": 14,
"options": { "legend": { "displayMode": "list", "placement": "bottom", "showLegend": true }, "tooltip": { "mode": "multi" } },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_cpu_usage_percent", "legendFormat": "CPU %", "refId": "A" }],
"title": "CPU Usage (%)",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": { "unit": "short", "custom": { "drawStyle": "line", "lineWidth": 1.5, "fillOpacity": 10 } },
"overrides": []
},
"gridPos": { "h": 6, "w": 8, "x": 8, "y": 29 },
"id": 15,
"options": { "legend": { "displayMode": "list", "placement": "bottom", "showLegend": true }, "tooltip": { "mode": "multi" } },
"targets": [
{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_load1", "legendFormat": "1m", "refId": "A" },
{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_load5", "legendFormat": "5m", "refId": "B" },
{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_load15", "legendFormat": "15m", "refId": "C" }
],
"title": "Load Average",
"type": "timeseries"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": {
"unit": "percent",
"thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "orange", "value": 80 }, { "color": "red", "value": 95 }] }
},
"overrides": []
},
"gridPos": { "h": 6, "w": 4, "x": 16, "y": 29 },
"id": 16,
"options": { "colorMode": "value", "graphMode": "none", "justifyMode": "center", "orientation": "auto", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "auto" },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_disk_used_percent{mountpoint=\"/\"}", "refId": "A" }],
"title": "Disk Used (/)",
"type": "stat"
},
{
"datasource": { "type": "prometheus", "uid": "victoriametrics" },
"fieldConfig": {
"defaults": { "unit": "s" },
"overrides": []
},
"gridPos": { "h": 6, "w": 4, "x": 20, "y": 29 },
"id": 17,
"options": { "colorMode": "value", "graphMode": "none", "justifyMode": "center", "orientation": "auto", "reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false }, "textMode": "auto" },
"targets": [{ "datasource": { "type": "prometheus", "uid": "victoriametrics" }, "expr": "opnsense_uptime_seconds", "refId": "A" }],
"title": "Uptime",
"type": "stat"
}
],
"refresh": "15s",
"schemaVersion": 39,
"tags": ["opnsense", "wan", "network"],
"templating": { "list": [] },
"time": { "from": "now-6h", "to": "now" },
"timepicker": {},
"timezone": "",
"title": "OPNsense — Multi-WAN & Router",
"uid": "opnsense-wan",
"version": 1
}
@@ -0,0 +1,817 @@
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "Prometheus",
"description": "Prometheus as the datasource is obligatory",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "7.4.5"
},
{
"type": "panel",
"id": "graph",
"name": "Graph",
"version": ""
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "table",
"name": "Table",
"version": ""
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": 14282,
"graphTooltip": 0,
"id": null,
"iteration": 1617715580880,
"links": [],
"panels": [
{
"collapsed": false,
"datasource": "victoriametrics",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"id": 8,
"panels": [],
"title": "CPU",
"type": "row"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "victoriametrics",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 24,
"x": 0,
"y": 1
},
"hiddenSeries": false,
"id": 15,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null as zero",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": true,
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(container_cpu_usage_seconds_total{instance=~\"$host\",container_label_com_docker_compose_service=~\"$container\",container_label_com_docker_compose_service=~\".+\"}[5m])) by (container_label_com_docker_compose_service) *100",
"hide": false,
"interval": "",
"legendFormat": "{{container_label_com_docker_compose_service}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "CPU Usage",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:606",
"format": "percent",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:607",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"collapsed": false,
"datasource": "victoriametrics",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 8
},
"id": 11,
"panels": [],
"title": "Memory",
"type": "row"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "victoriametrics",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 9
},
"hiddenSeries": false,
"id": 9,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null as zero",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": true,
"steppedLine": false,
"targets": [
{
"expr": "sum(container_memory_rss{instance=~\"$host\",container_label_com_docker_compose_service=~\"$container\",container_label_com_docker_compose_service=~\".+\"}) by (container_label_com_docker_compose_service)",
"hide": false,
"interval": "",
"legendFormat": "{{container_label_com_docker_compose_service}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Memory Usage",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:606",
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:607",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "victoriametrics",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 9
},
"hiddenSeries": false,
"id": 14,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null as zero",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": true,
"steppedLine": false,
"targets": [
{
"expr": "sum(container_memory_cache{instance=~\"$host\",container_label_com_docker_compose_service=~\"$container\",container_label_com_docker_compose_service=~\".+\"}) by (container_label_com_docker_compose_service)",
"hide": false,
"interval": "",
"legendFormat": "{{container_label_com_docker_compose_service}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Memory Cached",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:606",
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:607",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"collapsed": false,
"datasource": "victoriametrics",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 17
},
"id": 2,
"panels": [],
"title": "Network",
"type": "row"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "victoriametrics",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 18
},
"hiddenSeries": false,
"id": 4,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"hideEmpty": false,
"hideZero": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"sideWidth": null,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(container_network_receive_bytes_total{instance=~\"$host\",container_label_com_docker_compose_service=~\"$container\",container_label_com_docker_compose_service=~\".+\"}[5m])) by (container_label_com_docker_compose_service)",
"hide": false,
"interval": "",
"legendFormat": "{{container_label_com_docker_compose_service}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Received Network Traffic",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:674",
"format": "Bps",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:675",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "victoriametrics",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 18
},
"hiddenSeries": false,
"id": 6,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(container_network_transmit_bytes_total{instance=~\"$host\",container_label_com_docker_compose_service=~\"$container\",container_label_com_docker_compose_service=~\".+\"}[5m])) by (container_label_com_docker_compose_service)",
"interval": "",
"legendFormat": "{{container_label_com_docker_compose_service}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Sent Network Traffic",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:832",
"format": "Bps",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:833",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"collapsed": false,
"datasource": "victoriametrics",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 26
},
"id": 19,
"panels": [],
"title": "Misc",
"type": "row"
},
{
"datasource": "victoriametrics",
"fieldConfig": {
"defaults": {
"custom": {
"align": null,
"filterable": false
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "id"
},
"properties": [
{
"id": "custom.width",
"value": 260
}
]
},
{
"matcher": {
"id": "byName",
"options": "Running"
},
"properties": [
{
"id": "unit",
"value": "d"
},
{
"id": "decimals",
"value": 1
},
{
"id": "custom.displayMode",
"value": "color-text"
},
{
"id": "color",
"value": {
"fixedColor": "dark-green",
"mode": "fixed"
}
}
]
}
]
},
"gridPos": {
"h": 10,
"w": 24,
"x": 0,
"y": 27
},
"id": 17,
"options": {
"showHeader": true,
"sortBy": []
},
"pluginVersion": "7.4.5",
"targets": [
{
"expr": "(time() - container_start_time_seconds{instance=~\"$host\",container_label_com_docker_compose_service=~\"$container\",container_label_com_docker_compose_service=~\".+\"})/86400",
"format": "table",
"instant": true,
"interval": "",
"legendFormat": "{{container_label_com_docker_compose_service}}",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Containers Info",
"transformations": [
{
"id": "filterFieldsByName",
"options": {
"include": {
"names": [
"container_label_com_docker_compose_project",
"container_label_com_docker_compose_project_working_dir",
"image",
"instance",
"name",
"Value",
"container_label_com_docker_compose_service"
]
}
}
},
{
"id": "organize",
"options": {
"excludeByName": {},
"indexByName": {},
"renameByName": {
"Value": "Running",
"container_label_com_docker_compose_project": "Label",
"container_label_com_docker_compose_project_working_dir": "Working dir",
"container_label_com_docker_compose_service": "Service",
"image": "Registry Image",
"instance": "Instance",
"name": "Name"
}
}
}
],
"type": "table"
}
],
"schemaVersion": 27,
"style": "dark",
"tags": [
"cadvisor",
"docker"
],
"templating": {
"list": [
{
"allValue": ".*",
"current": {},
"datasource": "victoriametrics",
"definition": "label_values({__name__=~\"container.*\"},instance)",
"description": null,
"error": null,
"hide": 0,
"includeAll": true,
"label": "Host",
"multi": false,
"name": "host",
"options": [],
"query": {
"query": "label_values({__name__=~\"container.*\"},instance)",
"refId": "Prometheus-host-Variable-Query"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 5,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allValue": ".*",
"current": {},
"datasource": "victoriametrics",
"definition": "label_values(container_cpu_usage_seconds_total{instance=~\"$host\",container_label_com_docker_compose_service=~\".+\"}, container_label_com_docker_compose_service)",
"description": null,
"error": null,
"hide": 0,
"includeAll": true,
"label": "Container",
"multi": false,
"name": "container",
"options": [],
"query": {
"query": "label_values(container_cpu_usage_seconds_total{instance=~\"$host\",container_label_com_docker_compose_service=~\".+\"}, container_label_com_docker_compose_service)",
"refId": "Prometheus-container-Variable-Query"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Cadvisor exporter",
"uid": "pMEd7m0Mz",
"version": 1,
"description": "Simple exporter for cadvisor only"
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,338 @@
#!/usr/bin/env python3
"""Lightweight Prometheus exporter for OPNsense gateways, interfaces, pf, and system metrics."""
import base64
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
import json
import os
import re
import ssl
import sys
import urllib.error
import urllib.request
API_URL = os.environ.get("OPNSENSE_API_URL", "https://192.168.1.1:4433").rstrip("/")
API_KEY = os.environ.get("OPNSENSE_API_KEY", "")
API_SECRET = os.environ.get("OPNSENSE_API_SECRET", "")
VERIFY_TLS = os.environ.get("OPNSENSE_VERIFY_TLS", "false").lower() in ("1", "true", "yes")
LISTEN_PORT = int(os.environ.get("OPNSENSE_EXPORTER_PORT", "9105"))
TIMEOUT = float(os.environ.get("OPNSENSE_API_TIMEOUT", "5"))
def _ssl_context() -> ssl.SSLContext:
ctx = ssl.create_default_context()
if not VERIFY_TLS:
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
return ctx
def _auth_header() -> str:
raw = f"{API_KEY}:{API_SECRET}".encode("utf-8")
return "Basic " + base64.b64encode(raw).decode("ascii")
def _api_get(path: str):
req = urllib.request.Request(
f"{API_URL}{path}",
headers={
"Authorization": _auth_header(),
"Accept": "application/json",
},
method="GET",
)
with urllib.request.urlopen(req, context=_ssl_context(), timeout=TIMEOUT) as resp:
return json.loads(resp.read().decode("utf-8"))
def _esc(val: str) -> str:
return str(val).replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n")
def _labels(mapping: dict[str, str]) -> str:
parts = [f'{k}="{_esc(v)}"' for k, v in mapping.items()]
return "{" + ",".join(parts) + "}"
def _parse_ms(text: str):
m = re.match(r"^\s*([0-9]+(?:\.[0-9]+)?)\s*ms\s*$", str(text or ""))
return float(m.group(1)) / 1000.0 if m else None
def _parse_pct(text: str):
m = re.match(r"^\s*([0-9]+(?:\.[0-9]+)?)\s*%\s*$", str(text or ""))
return float(m.group(1)) / 100.0 if m else None
def _parse_uptime(text: str):
# Examples: "3 days, 16:05:44", "16:05:44", "1 day, 02:10:00"
m = re.match(r"^(?:(\d+)\s+days?,\s*)?(\d+):(\d+):(\d+)$", str(text or "").strip())
if not m:
return None
days = int(m.group(1) or 0)
hours, mins, secs = int(m.group(2)), int(m.group(3)), int(m.group(4))
return days * 86400 + hours * 3600 + mins * 60 + secs
def collect_metrics() -> str:
lines: list[str] = []
gateways_data = _api_get("/api/routing/settings/searchGateway").get("rows", [])
routes_data = _api_get("/api/diagnostics/interface/getRoutes")
ifaces_data = _api_get("/api/interfaces/overview/interfacesInfo").get("rows", [])
ifstats_data = _api_get("/api/diagnostics/interface/getInterfaceStatistics").get("statistics", {})
pf_data = _api_get("/api/diagnostics/firewall/pfStatistics/info").get("info", {})
sys_res = _api_get("/api/diagnostics/system/systemResources")
sys_time = _api_get("/api/diagnostics/system/systemTime")
sys_disk = _api_get("/api/diagnostics/system/systemDisk").get("devices", [])
sys_act = _api_get("/api/diagnostics/activity/getActivity").get("headers", [])
services_data = _api_get("/api/core/service/search").get("rows", [])
# Active IPv4 default route from kernel routing table
active_default_gw = None
active_default_if = None
for r in routes_data:
if r.get("proto") == "ipv4" and r.get("destination") == "default":
active_default_gw = r.get("gateway")
active_default_if = r.get("netif")
break
# Gateways (dpinger)
lines.extend([
"# HELP opnsense_gateway_status Gateway online status (1=Online, 0=Offline)",
"# TYPE opnsense_gateway_status gauge",
"# HELP opnsense_gateway_configured_default Configured default gateway flag",
"# TYPE opnsense_gateway_configured_default gauge",
"# HELP opnsense_gateway_default Active kernel default route flag (1=active default)",
"# TYPE opnsense_gateway_default gauge",
"# HELP opnsense_gateway_delay_seconds Gateway monitor RTT in seconds",
"# TYPE opnsense_gateway_delay_seconds gauge",
"# HELP opnsense_gateway_stddev_seconds Gateway monitor RTT stddev in seconds",
"# TYPE opnsense_gateway_stddev_seconds gauge",
"# HELP opnsense_gateway_loss_ratio Gateway monitor packet loss ratio (0.0-1.0)",
"# TYPE opnsense_gateway_loss_ratio gauge",
])
for gw in gateways_data:
name = gw.get("name", "")
descr = gw.get("interface_descr") or gw.get("descr") or name
iface = gw.get("interface", "")
device = gw.get("if", "")
monitor = gw.get("monitor", "")
gw_addr = gw.get("gateway", "")
lbl = _labels({
"gateway": name,
"descr": descr,
"interface": iface,
"device": device,
"monitor": monitor,
})
online = 1 if gw.get("status") == "Online" else 0
lines.append(f"opnsense_gateway_status{lbl} {online}")
lines.append(f"opnsense_gateway_configured_default{lbl} {1 if gw.get('defaultgw') else 0}")
is_active_default = 1 if (
active_default_gw and active_default_if
and gw_addr == active_default_gw and device == active_default_if
) else 0
lines.append(f"opnsense_gateway_default{lbl} {is_active_default}")
loss = _parse_pct(gw.get("loss"))
if loss is not None:
lines.append(f"opnsense_gateway_loss_ratio{lbl} {loss}")
if online:
delay = _parse_ms(gw.get("delay"))
stddev = _parse_ms(gw.get("stddev"))
if delay is not None:
lines.append(f"opnsense_gateway_delay_seconds{lbl} {delay}")
if stddev is not None:
lines.append(f"opnsense_gateway_stddev_seconds{lbl} {stddev}")
# Interfaces status & traffic counters
device_meta: dict[str, tuple[str, str]] = {}
lines.extend([
"# HELP opnsense_interface_up Interface operational status (1=up, 0=down)",
"# TYPE opnsense_interface_up gauge",
])
for iface in ifaces_data:
ident = iface.get("identifier") or ""
device = iface.get("device") or ""
descr = iface.get("description") or ident or device
if not ident or not device:
continue
device_meta[device] = (ident, descr)
up = 1 if iface.get("status") == "up" else 0
lbl = _labels({"interface": ident, "device": device, "descr": descr})
lines.append(f"opnsense_interface_up{lbl} {up}")
lines.extend([
"# HELP opnsense_interface_rx_bytes_total Received bytes on interface",
"# TYPE opnsense_interface_rx_bytes_total counter",
"# HELP opnsense_interface_tx_bytes_total Transmitted bytes on interface",
"# TYPE opnsense_interface_tx_bytes_total counter",
"# HELP opnsense_interface_rx_packets_total Received packets on interface",
"# TYPE opnsense_interface_rx_packets_total counter",
"# HELP opnsense_interface_tx_packets_total Transmitted packets on interface",
"# TYPE opnsense_interface_tx_packets_total counter",
"# HELP opnsense_interface_rx_errors_total Receive errors on interface",
"# TYPE opnsense_interface_rx_errors_total counter",
"# HELP opnsense_interface_tx_errors_total Transmit errors on interface",
"# TYPE opnsense_interface_tx_errors_total counter",
"# HELP opnsense_interface_dropped_packets_total Dropped packets on interface",
"# TYPE opnsense_interface_dropped_packets_total counter",
])
seen_devices: set[str] = set()
for stat in ifstats_data.values():
device = stat.get("name")
if not device or device not in device_meta or device in seen_devices:
continue
if stat.get("received-bytes") is None:
continue
seen_devices.add(device)
ident, descr = device_meta[device]
lbl = _labels({"interface": ident, "device": device, "descr": descr})
lines.append(f"opnsense_interface_rx_bytes_total{lbl} {stat['received-bytes']}")
lines.append(f"opnsense_interface_tx_bytes_total{lbl} {stat['sent-bytes']}")
lines.append(f"opnsense_interface_rx_packets_total{lbl} {stat['received-packets']}")
lines.append(f"opnsense_interface_tx_packets_total{lbl} {stat['sent-packets']}")
lines.append(f"opnsense_interface_rx_errors_total{lbl} {stat.get('received-errors') or 0}")
lines.append(f"opnsense_interface_tx_errors_total{lbl} {stat.get('send-errors') or 0}")
lines.append(f"opnsense_interface_dropped_packets_total{lbl} {stat.get('dropped-packets') or 0}")
# pf state table
state_table = pf_data.get("state-table", {})
pf_current = state_table.get("current-entries", {}).get("total")
pf_inserts = state_table.get("inserts", {}).get("total")
pf_removals = state_table.get("removals", {}).get("total")
if pf_current is not None:
lines.extend([
"# HELP opnsense_pf_states_current Current active pf states",
"# TYPE opnsense_pf_states_current gauge",
f"opnsense_pf_states_current {pf_current}",
])
if pf_inserts is not None and pf_removals is not None:
lines.extend([
"# HELP opnsense_pf_state_inserts_total Total pf state insertions",
"# TYPE opnsense_pf_state_inserts_total counter",
f"opnsense_pf_state_inserts_total {pf_inserts}",
"# HELP opnsense_pf_state_removals_total Total pf state removals",
"# TYPE opnsense_pf_state_removals_total counter",
f"opnsense_pf_state_removals_total {pf_removals}",
])
# System memory, load, CPU, disk & uptime
mem = sys_res.get("memory", {})
if mem.get("total") is not None and mem.get("used") is not None:
lines.extend([
"# HELP opnsense_memory_total_bytes Total physical memory in bytes",
"# TYPE opnsense_memory_total_bytes gauge",
f"opnsense_memory_total_bytes {mem['total']}",
"# HELP opnsense_memory_used_bytes Used memory in bytes",
"# TYPE opnsense_memory_used_bytes gauge",
f"opnsense_memory_used_bytes {mem['used']}",
])
load_parts = [p.strip() for p in str(sys_time.get("loadavg", "")).split(",") if p.strip()]
if len(load_parts) == 3:
lines.extend([
"# HELP opnsense_load1 1-minute system load average",
"# TYPE opnsense_load1 gauge",
f"opnsense_load1 {float(load_parts[0])}",
"# HELP opnsense_load5 5-minute system load average",
"# TYPE opnsense_load5 gauge",
f"opnsense_load5 {float(load_parts[1])}",
"# HELP opnsense_load15 15-minute system load average",
"# TYPE opnsense_load15 gauge",
f"opnsense_load15 {float(load_parts[2])}",
])
uptime_sec = _parse_uptime(sys_time.get("uptime"))
if uptime_sec is not None:
lines.extend([
"# HELP opnsense_uptime_seconds System uptime in seconds",
"# TYPE opnsense_uptime_seconds gauge",
f"opnsense_uptime_seconds {uptime_sec}",
])
for h in sys_act:
m = re.search(r"([0-9]+(?:\.[0-9]+)?)%\s*idle", str(h))
if m:
cpu_used = round(max(0.0, 100.0 - float(m.group(1))), 2)
lines.extend([
"# HELP opnsense_cpu_usage_percent Total CPU usage percentage",
"# TYPE opnsense_cpu_usage_percent gauge",
f"opnsense_cpu_usage_percent {cpu_used}",
])
break
lines.extend([
"# HELP opnsense_disk_used_percent Disk space used percentage",
"# TYPE opnsense_disk_used_percent gauge",
])
for dev in sys_disk:
mp = dev.get("mountpoint")
pct = dev.get("used_pct")
if mp and pct is not None:
lbl = _labels({
"mountpoint": mp,
"device": dev.get("device", ""),
"fstype": dev.get("type", ""),
})
lines.append(f"opnsense_disk_used_percent{lbl} {pct}")
# Services
lines.extend([
"# HELP opnsense_service_running OPNsense service status (1=running, 0=stopped)",
"# TYPE opnsense_service_running gauge",
])
for svc in services_data:
lbl = _labels({
"service_id": svc.get("id", ""),
"name": svc.get("name", ""),
})
lines.append(f"opnsense_service_running{lbl} {1 if svc.get('running') else 0}")
return "\n".join(lines) + "\n"
class MetricsHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/health":
self.send_response(200)
self.send_header("Content-Type", "text/plain")
self.end_headers()
self.wfile.write(b"ok\n")
return
if self.path != "/metrics":
self.send_response(404)
self.end_headers()
return
try:
body = collect_metrics().encode("utf-8")
self.send_response(200)
self.send_header("Content-Type", "text/plain; version=0.0.4; charset=utf-8")
self.end_headers()
self.wfile.write(body)
except (urllib.error.URLError, TimeoutError, json.JSONDecodeError, KeyError) as exc:
msg = f"# error collecting OPNsense metrics: {exc}\n".encode("utf-8")
self.send_response(503)
self.send_header("Content-Type", "text/plain; charset=utf-8")
self.end_headers()
self.wfile.write(msg)
def log_message(self, format, *args):
return
def main():
if not API_KEY or not API_SECRET:
print("OPNSENSE_API_KEY and OPNSENSE_API_SECRET must be set", file=sys.stderr)
sys.exit(1)
server = ThreadingHTTPServer(("0.0.0.0", LISTEN_PORT), MetricsHandler)
server.serve_forever()
if __name__ == "__main__":
main()
@@ -0,0 +1,44 @@
---
- name: Установить compose.yaml для стека мониторинга
ansible.builtin.template:
src: compose.yaml.j2
dest: "{{ monitoring_dir }}/compose.yaml"
owner: root
group: root
mode: "0644"
register: monitoring_compose
- name: Запустить стек мониторинга через Docker Compose
ansible.builtin.command: docker compose -f {{ monitoring_dir }}/compose.yaml up -d --remove-orphans
register: compose_up
changed_when: "'Started' in compose_up.stderr or 'Created' in compose_up.stderr or 'Recreated' in compose_up.stderr or 'Pulled' in compose_up.stderr"
- name: Пересоздать Xray Checker, чтобы подхватить метод проверки
ansible.builtin.command: docker compose -f {{ monitoring_dir }}/compose.yaml up -d --force-recreate --no-deps xray-checker
when: xray_checker_env is defined and xray_checker_env is changed
changed_when: true
- name: Пересоздать экспортер OPNsense при обновлении скрипта или окружения
ansible.builtin.command: docker compose -f {{ monitoring_dir }}/compose.yaml up -d --force-recreate --no-deps opnsense-exporter
when: >
(opnsense_exporter_env is defined and opnsense_exporter_env is changed) or
(opnsense_exporter_script is defined and opnsense_exporter_script is changed)
changed_when: true
- name: Дождаться VictoriaMetrics
ansible.builtin.uri:
url: "http://{{ ansible_host }}:8428/health"
status_code: 200
register: victoriametrics_health
retries: 20
delay: 2
until: victoriametrics_health.status == 200
- name: Дождаться vmalert
ansible.builtin.uri:
url: "http://127.0.0.1:8880/health"
status_code: 200
register: vmalert_health
retries: 20
delay: 2
until: vmalert_health.status == 200
@@ -0,0 +1,24 @@
---
- name: Создать базовые каталоги мониторинга
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
loop:
- { path: "{{ monitoring_dir }}", owner: "root", group: "root", mode: "0755" }
- { path: "{{ monitoring_dir }}/alertmanager", owner: "root", group: "root", mode: "0755" }
- { path: "{{ monitoring_dir }}/alertmanager_data", owner: "65534", group: "65534", mode: "0777" }
- { path: "{{ monitoring_dir }}/grafana", owner: "root", group: "root", mode: "0755" }
- { path: "{{ monitoring_dir }}/grafana_data", owner: "472", group: "472", mode: "0755" }
- { path: "{{ monitoring_dir }}/grafana/provisioning", owner: "root", group: "root", mode: "0755" }
- { path: "{{ monitoring_dir }}/grafana/provisioning/datasources", owner: "root", group: "root", mode: "0755" }
- { path: "{{ monitoring_dir }}/grafana/provisioning/dashboards", owner: "root", group: "root", mode: "0755" }
- { path: "{{ monitoring_dir }}/ntfy_data", owner: "root", group: "root", mode: "0777" }
- { path: "{{ monitoring_dir }}/alertmanager-ntfy", owner: "root", group: "root", mode: "0755" }
- { path: "{{ monitoring_dir }}/victoria-metrics-data", owner: "65534", group: "65534", mode: "0775" }
- { path: "{{ monitoring_dir }}/vmagent", owner: "root", group: "root", mode: "0755" }
- { path: "{{ monitoring_dir }}/vmagent/conf.d", owner: "root", group: "root", mode: "0755" }
- { path: "{{ monitoring_dir }}/vmalert", owner: "root", group: "root", mode: "0755" }
- { path: "{{ monitoring_dir }}/opnsense-exporter", owner: "root", group: "root", mode: "0755" }
@@ -0,0 +1,61 @@
---
- name: Установить источники данных Grafana
ansible.builtin.template:
src: grafana-datasources.yml.j2
dest: "{{ monitoring_dir }}/grafana/provisioning/datasources/prometheus.yml"
owner: root
group: root
mode: "0644"
register: grafana_datasources
- name: Установить провайдер дашбордов Grafana
ansible.builtin.template:
src: grafana-dashboards.yml.j2
dest: "{{ monitoring_dir }}/grafana/provisioning/dashboards/dashboards.yml"
owner: root
group: root
mode: "0644"
register: grafana_dashboard_provider
- name: Скопировать статические дашборды Grafana
ansible.builtin.copy:
src: dashboards/
dest: "{{ monitoring_dir }}/grafana/provisioning/dashboards/"
owner: root
group: root
mode: "0644"
register: grafana_dashboards
- name: Удалить старый дашборд Node Exporter Full
ansible.builtin.file:
path: "{{ monitoring_dir }}/grafana/provisioning/dashboards/node-exporter-full.json"
state: absent
register: grafana_old_dashboard
- name: Перезапустить Grafana, чтобы подхватить datasource
ansible.builtin.command: docker compose -f {{ monitoring_dir }}/compose.yaml restart grafana
when: grafana_datasources is changed or grafana_dashboards is changed or grafana_dashboard_provider is changed or grafana_old_dashboard is changed
changed_when: true
- name: Дождаться готовности Grafana
ansible.builtin.uri:
url: "http://127.0.0.1:3000/api/health"
status_code: 200
register: grafana_health
retries: 20
delay: 2
until: grafana_health.status == 200
- name: Обеспечить имя и email администратора в базе Grafana
ansible.builtin.command: >
python3 -c "import sqlite3; conn = sqlite3.connect('{{ monitoring_dir }}/grafana_data/grafana.db'); conn.execute('UPDATE user SET login=\"{{ grafana_admin_user }}\", email=\"{{ grafana_admin_email }}\" WHERE id=1'); conn.commit()"
failed_when: false
changed_when: false
- name: Синхронизировать пароль администратора Grafana с Infisical
ansible.builtin.command:
cmd: docker exec -i monitoring-grafana grafana cli admin reset-admin-password --user-id 1 --password-from-stdin
stdin: "{{ grafana_admin_password }}"
no_log: true
changed_when: false
when: grafana_admin_password is defined and grafana_admin_password | length > 0
@@ -0,0 +1,20 @@
---
- name: Создать каталоги стека мониторинга
ansible.builtin.include_tasks: dirs.yml
tags: [monitoring, monitoring_dirs]
- name: Собрать таргеты и конфиги VictoriaMetrics / vmagent / vmalert / Alertmanager
ansible.builtin.include_tasks: vm.yml
tags: [monitoring, monitoring_vm]
- name: Запустить Docker Compose стека мониторинга
ansible.builtin.include_tasks: compose.yml
tags: [monitoring, monitoring_compose]
- name: Настроить Ntfy
ansible.builtin.include_tasks: ntfy.yml
tags: [monitoring, monitoring_ntfy]
- name: Настроить Grafana и дашборды
ansible.builtin.include_tasks: grafana.yml
tags: [monitoring, monitoring_grafana]
@@ -0,0 +1,26 @@
---
- name: Дождаться готовности Ntfy
ansible.builtin.uri:
url: "http://127.0.0.1:80/v1/health"
status_code: 200
register: ntfy_health
retries: 15
delay: 2
until: ntfy_health.status == 200
- name: Создать или обновить пользователя администратора в Ntfy
ansible.builtin.command: >
docker exec -i -e NTFY_PASSWORD="{{ ntfy_admin_password }}"
monitoring-ntfy ntfy user add --role=admin --ignore-exists "{{ ntfy_admin_user }}"
register: ntfy_user_add
changed_when: "'added' in ntfy_user_add.stdout or 'added' in ntfy_user_add.stderr"
failed_when: false
no_log: true
- name: Обновить пароль администратора в Ntfy
ansible.builtin.command: >
docker exec -i -e NTFY_PASSWORD="{{ ntfy_admin_password }}"
monitoring-ntfy ntfy user change-pass "{{ ntfy_admin_user }}"
changed_when: false
failed_when: false
no_log: true
@@ -0,0 +1,137 @@
---
- name: Сбросить список целей scrape node-exporter
ansible.builtin.set_fact:
monitoring_scrape_targets: []
- name: Собрать цели scrape node-exporter из inventory
ansible.builtin.set_fact:
monitoring_scrape_targets: "{{ monitoring_scrape_targets + [target] }}"
vars:
target:
name: "{{ item }}"
address: "{{ hostvars[item].monitoring_scrape_address | default(hostvars[item].ansible_host) }}"
port: "{{ hostvars[item].monitoring_node_exporter_port | default(monitoring_node_exporter_port) }}"
loop: "{{ groups['all'] | sort }}"
when:
- item not in monitoring_scrape_exclude_hosts
- hostvars[item].monitoring_scrape_enabled | default(true) | bool
- name: Проверить, что есть хотя бы одна цель node-exporter
ansible.builtin.assert:
that:
- monitoring_scrape_targets | length > 0
fail_msg: "Нет целей scrape: проверьте inventory и monitoring_scrape_exclude_hosts."
- name: Показать цели scrape node-exporter
ansible.builtin.debug:
msg: "{{ monitoring_scrape_targets | map(attribute='name') | list | sort }}"
- name: Установить правила алертов vmalert
ansible.builtin.template:
src: alerts.yml.j2
dest: "{{ monitoring_dir }}/vmalert/alerts.yml"
owner: root
group: root
mode: "0644"
- name: Установить конфигурацию Alertmanager
ansible.builtin.template:
src: alertmanager.yml.j2
dest: "{{ monitoring_dir }}/alertmanager/alertmanager.yml"
owner: root
group: root
mode: "0644"
- name: Установить конфигурацию alertmanager-ntfy
ansible.builtin.template:
src: alertmanager-ntfy.yml.j2
dest: "{{ monitoring_dir }}/alertmanager-ntfy/config.yml"
owner: root
group: root
mode: "0644"
- name: Конфиг vmagent на core-mon
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: "0644"
loop:
- { src: vmagent-scrape.yml.j2, dest: "{{ monitoring_dir }}/vmagent/scrape.yml" }
- { src: vmagent-nodeexporter.yml.j2, dest: "{{ monitoring_dir }}/vmagent/conf.d/nodeexporter.yml" }
- { src: vmagent-cadvisor.yml.j2, dest: "{{ monitoring_dir }}/vmagent/conf.d/cadvisor.yml" }
- name: Убрать scrape Xray Checker без ссылки подписки
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- "{{ monitoring_dir }}/vmagent/conf.d/xraychecker.yml"
- "{{ monitoring_dir }}/xray-checker.env"
when: xray_checker_subscription_url | length == 0
- name: Ссылки подписки для Xray Checker нет
ansible.builtin.debug:
msg: "Ссылки Xray Checker нет, контейнер не запускается."
when: xray_checker_subscription_url | length == 0
- name: Файл окружения Xray Checker
ansible.builtin.template:
src: xray-checker.env.j2
dest: "{{ monitoring_dir }}/xray-checker.env"
owner: root
group: root
mode: "0600"
no_log: true
register: xray_checker_env
when: xray_checker_subscription_url | length > 0
- name: Scrape Xray Checker
ansible.builtin.template:
src: vmagent-xray.yml.j2
dest: "{{ monitoring_dir }}/vmagent/conf.d/xraychecker.yml"
owner: root
group: root
mode: "0644"
when: xray_checker_subscription_url | length > 0
- name: Убрать scrape OPNsense без API-ключей
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- "{{ monitoring_dir }}/vmagent/conf.d/opnsense.yml"
- "{{ monitoring_dir }}/opnsense-exporter.env"
when: not (opnsense_exporter_enabled | bool)
- name: Скрипт экспортера OPNsense
ansible.builtin.copy:
src: opnsense-exporter/exporter.py
dest: "{{ monitoring_dir }}/opnsense-exporter/exporter.py"
owner: root
group: root
mode: "0755"
register: opnsense_exporter_script
when: opnsense_exporter_enabled | bool
- name: Файл окружения экспортера OPNsense
ansible.builtin.template:
src: opnsense-exporter.env.j2
dest: "{{ monitoring_dir }}/opnsense-exporter.env"
owner: root
group: root
mode: "0600"
no_log: true
register: opnsense_exporter_env
when: opnsense_exporter_enabled | bool
- name: Scrape OPNsense
ansible.builtin.template:
src: vmagent-opnsense.yml.j2
dest: "{{ monitoring_dir }}/vmagent/conf.d/opnsense.yml"
owner: root
group: root
mode: "0644"
when: opnsense_exporter_enabled | bool
@@ -0,0 +1,37 @@
http:
addr: :8000
ntfy:
baseurl: http://ntfy:80
auth:
basic:
username: "{{ ntfy_admin_user }}"
password: "{{ ntfy_admin_password }}"
notification:
topic: "{{ ntfy_default_topic }}"
priority: |
status == "firing" ? (labels.severity == "critical" ? "urgent" : "high") : "default"
tags:
- tag: white_check_mark
condition: status == "resolved"
- tag: rotating_light
condition: status == "firing" && labels.severity == "critical"
- tag: warning
condition: status == "firing" && labels.severity != "critical"
{% raw %}
templates:
title: |
{{ if eq .Status "resolved" }}✅ [Восстановлено] {{ index .Labels "alertname" }}: {{ if index .Labels "host" }}{{ index .Labels "host" }}{{ else }}{{ index .Labels "instance" }}{{ end }}{{ else }}🚨 [СБОЙ] {{ index .Annotations "summary" }}{{ end }}
description: |
{{ if eq .Status "resolved" }}Работа сервиса полностью восстановлена.{{ else }}{{ index .Annotations "description" }}{{ end }}
Хост: {{ if index .Labels "host" }}{{ index .Labels "host" }}{{ else }}{{ index .Labels "instance" }}{{ end }}
Критичность: {{ index .Labels "severity" }}
headers:
X-Click: |
https://graf.gunihome.ru
X-Actions: |
view, 📊 Открыть Grafana, https://graf.gunihome.ru, clear=true
{% endraw %}
async: false
@@ -0,0 +1,16 @@
global:
resolve_timeout: 5m
route:
group_by: ['alertname', 'instance', 'severity']
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
receiver: 'ntfy'
receivers:
- name: 'ntfy'
webhook_configs:
- url: "http://alertmanager-ntfy:8000/hook"
send_resolved: true
@@ -0,0 +1,318 @@
#jinja2: variable_start_string:'[[', variable_end_string:']]', block_start_string:'[%', block_end_string:'%]'
groups:
- name: homelab_alerts
rules:
- alert: HostDown
expr: up{job="integrations/node_exporter"} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "Сервис или узел {{ $labels.instance }} недоступен"
description: "Экспортер {{ $labels.instance }} (job={{ $labels.job }}) не отвечает более 2 минут."
# Pull-цель пишет up=0, push-хост (core-mon, core-net, ger-nod-02) просто перестаёт слать ряды.
# tlast ловит паузу до 30 минут, absent держит алерт, пока ряд не вернётся.
- alert: HostMetricsStale
expr: |
(
time() - tlast_over_time(up{job="integrations/node_exporter"}[30m]) > 180
)
[% for h in (['core-mon', 'core-net', 'core-secrets', 'rus-central'] + (groups['exit_nodes'] | default([]))) | unique | sort %]
or absent_over_time(up{job="integrations/node_exporter",instance="[[ h ]]"}[30m])
[% endfor %]
for: 1m
labels:
severity: critical
annotations:
summary: "Нет свежих метрик узла {{ $labels.instance }}"
description: "node_exporter {{ $labels.instance }} не присылает up дольше 3 минут."
- alert: HostDiskSpaceLow
expr: |
(
node_filesystem_avail_bytes{job="integrations/node_exporter",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs|rootfs",mountpoint!~"/boot(/efi)?"}
/
node_filesystem_size_bytes{job="integrations/node_exporter",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs|rootfs",mountpoint!~"/boot(/efi)?"}
) * 100 < 15
and
(
node_filesystem_avail_bytes{job="integrations/node_exporter",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs|rootfs",mountpoint!~"/boot(/efi)?"}
/
node_filesystem_size_bytes{job="integrations/node_exporter",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs|rootfs",mountpoint!~"/boot(/efi)?"}
) * 100 >= 5
for: 5m
labels:
severity: warning
annotations:
summary: "Мало свободного места на {{ $labels.instance }} {{ $labels.mountpoint }}"
description: "На {{ $labels.mountpoint }} ({{ $labels.instance }}) свободно меньше 15%."
- alert: HostDiskSpaceCritical
expr: |
(
node_filesystem_avail_bytes{job="integrations/node_exporter",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs|rootfs",mountpoint!~"/boot(/efi)?"}
/
node_filesystem_size_bytes{job="integrations/node_exporter",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs|rootfs",mountpoint!~"/boot(/efi)?"}
) * 100 < 5
for: 5m
labels:
severity: critical
annotations:
summary: "Заканчивается место на {{ $labels.instance }} {{ $labels.mountpoint }}"
description: "На {{ $labels.mountpoint }} ({{ $labels.instance }}) свободно меньше 5%."
- alert: HostInodesLow
expr: |
(
node_filesystem_files_free{job="integrations/node_exporter",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs|rootfs",mountpoint!~"/boot(/efi)?"}
/
node_filesystem_files{job="integrations/node_exporter",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs|rootfs",mountpoint!~"/boot(/efi)?"}
) * 100 < 10
for: 10m
labels:
severity: warning
annotations:
summary: "Мало свободных inode на {{ $labels.instance }} {{ $labels.mountpoint }}"
description: "На {{ $labels.mountpoint }} ({{ $labels.instance }}) свободно меньше 10% inode."
- alert: HostFilesystemReadonly
expr: |
node_filesystem_readonly{job="integrations/node_exporter",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs|rootfs",mountpoint!~"/boot(/efi)?"} == 1
for: 5m
labels:
severity: critical
annotations:
summary: "Файловая система {{ $labels.instance }} {{ $labels.mountpoint }} только для чтения"
description: "{{ $labels.mountpoint }} на {{ $labels.instance }} смонтирована readonly."
- alert: HostFilesystemDeviceError
expr: |
node_filesystem_device_error{job="integrations/node_exporter",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs|rootfs",mountpoint!~"/boot(/efi)?"} == 1
for: 5m
labels:
severity: critical
annotations:
summary: "Ошибка устройства {{ $labels.instance }} {{ $labels.mountpoint }}"
description: "node_exporter видит ошибку устройства на {{ $labels.mountpoint }} ({{ $labels.instance }})."
- alert: HostOomKill
expr: increase(node_vmstat_oom_kill{job="integrations/node_exporter"}[5m]) > 0
for: 1m
labels:
severity: critical
annotations:
summary: "OOM killer на {{ $labels.instance }}"
description: "Ядро {{ $labels.instance }} завершило процесс из-за нехватки памяти."
- alert: HostHighCpuLoad
expr: 100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 90
for: 10m
labels:
severity: warning
annotations:
summary: "Высокая нагрузка CPU на {{ $labels.instance }}"
description: "Утилизация CPU превышает 90% более 10 минут."
- alert: HostHighMemoryUsage
expr: (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100 > 90
for: 10m
labels:
severity: warning
annotations:
summary: "Мало оперативной памяти на {{ $labels.instance }}"
description: "Использование RAM превышает 90% более 10 минут."
- alert: CadvisorDown
expr: up{job="integrations/cAdvisor"} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "cAdvisor {{ $labels.instance }} недоступен"
description: "Scrape cAdvisor на {{ $labels.instance }} возвращает up=0 более 2 минут."
- alert: CadvisorMetricsStale
expr: |
(
time() - tlast_over_time(up{job="integrations/cAdvisor"}[30m]) > 180
)
[% for h in (['core-mon', 'core-net', 'core-secrets', 'rus-central'] + (groups['exit_nodes'] | default([]))) | unique | sort %]
or absent_over_time(up{job="integrations/cAdvisor",instance="[[ h ]]"}[30m])
[% endfor %]
for: 1m
labels:
severity: critical
annotations:
summary: "Нет свежих метрик cAdvisor {{ $labels.instance }}"
description: "cAdvisor {{ $labels.instance }} не присылает up дольше 3 минут."
- alert: ContainerRestarting
expr: |
changes(container_start_time_seconds{container_label_com_docker_compose_service!=""}[15m]) > 2
for: 2m
labels:
severity: warning
annotations:
summary: "Контейнер {{ $labels.container_label_com_docker_compose_service }} перезапускается на {{ $labels.instance }}"
description: "Сервис Compose {{ $labels.container_label_com_docker_compose_service }} на {{ $labels.instance }} менял время старта больше двух раз за 15 минут."
- alert: RemnawaveDown
expr: up{job="remnawave"} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "Панель Remnawave недоступна"
description: "Scrape remnawave ({{ $labels.instance }}) возвращает up=0 более 2 минут."
- alert: RemnawaveMetricsStale
expr: |
(
time() - tlast_over_time(up{job="remnawave"}[30m]) > 180
)
or absent_over_time(up{job="remnawave",instance="core-net"}[30m])
for: 1m
labels:
severity: critical
annotations:
summary: "Нет свежих метрик Remnawave"
description: "Панель Remnawave на {{ $labels.instance }} не присылает up дольше 3 минут."
- alert: RemnawaveNodeNotActive
expr: remnawave_node_status != 1
for: 2m
labels:
severity: critical
annotations:
summary: "Узел Remnawave не активен"
description: "remnawave_node_status узла {{ $labels.node_uuid }} на {{ $labels.instance }} не равен 1."
- alert: XrayCheckerDown
expr: up{job="xray_checker"} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "xray-checker недоступен"
description: "Scrape xray_checker ({{ $labels.instance }}) возвращает up=0 более 2 минут."
- alert: XrayCheckerMetricsStale
expr: |
(
time() - tlast_over_time(up{job="xray_checker"}[30m]) > 180
)
or absent_over_time(up{job="xray_checker",instance="core-mon"}[30m])
for: 1m
labels:
severity: critical
annotations:
summary: "Нет свежих метрик xray-checker"
description: "xray-checker на {{ $labels.instance }} не присылает up дольше 3 минут."
- alert: XrayProxyDown
expr: xray_proxy_status != 1
for: 2m
labels:
severity: critical
annotations:
summary: "Прокси {{ $labels.name }} не проходит проверку"
description: "xray_proxy_status {{ $labels.name }} ({{ $labels.address }}) не равен 1."
[% if opnsense_exporter_enabled | bool %]
- alert: OpnsenseExporterDown
expr: up{job="opnsense"} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "Экспортер OPNsense недоступен"
description: "Scrape opnsense ({{ $labels.instance }}) возвращает up=0 более 2 минут."
- alert: OpnsenseMetricsStale
expr: |
(
time() - tlast_over_time(up{job="opnsense"}[30m]) > 180
)
or absent_over_time(up{job="opnsense",instance="opnsense"}[30m])
for: 1m
labels:
severity: critical
annotations:
summary: "Нет свежих метрик OPNsense"
description: "opnsense-exporter не присылает up дольше 3 минут."
# Мониторим отвал только постоянных каналов (NorCom и MTC); WAN_0 (Iterika) работает по расписанию.
- alert: OpnsenseGatewayDown
expr: opnsense_gateway_status{gateway=~"NORCOM_DHCP|WAN1"} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "Провайдер OPNsense {{ $labels.gateway }} ({{ $labels.descr }}) недоступен"
description: "Шлюз {{ $labels.gateway }} (монитор {{ $labels.monitor }}) в статусе Offline более 2 минут."
- alert: OpnsenseGatewayPacketLoss
expr: opnsense_gateway_loss_ratio{gateway=~"NORCOM_DHCP|WAN1"} > 0.1
for: 3m
labels:
severity: warning
annotations:
summary: "Потери пакетов на {{ $labels.gateway }} ({{ $labels.descr }})"
description: "Потери на шлюзе {{ $labels.gateway }} превышают 10% более 3 минут."
- alert: OpnsenseGatewayHighLatency
expr: opnsense_gateway_delay_seconds{gateway=~"NORCOM_DHCP|WAN1"} > 0.25
for: 5m
labels:
severity: warning
annotations:
summary: "Высокая задержка на {{ $labels.gateway }} ({{ $labels.descr }})"
description: "RTT до {{ $labels.monitor }} через {{ $labels.gateway }} превышает 250 ms более 5 минут."
# Уведомление при переключении default-маршрута на резерв (включая WAN_0 / Iterika).
- alert: OpnsenseFailoverActive
expr: opnsense_gateway_default{gateway!="NORCOM_DHCP"} == 1
for: 30s
labels:
severity: warning
annotations:
summary: "OPNsense переключился на резерв: {{ $labels.gateway }} ({{ $labels.descr }})"
description: "Активный default-маршрут ушёл с NORCOM_DHCP на {{ $labels.gateway }} ({{ $labels.descr }}, {{ $labels.device }})."
- alert: OpnsenseDiskSpaceLow
expr: opnsense_disk_used_percent{mountpoint="/"} > 85 and opnsense_disk_used_percent{mountpoint="/"} <= 95
for: 5m
labels:
severity: warning
annotations:
summary: "Мало свободного места на OPNsense (/)"
description: "Корневой раздел / на OPNsense заполнен более чем на 85%."
- alert: OpnsenseDiskSpaceCritical
expr: opnsense_disk_used_percent{mountpoint="/"} > 95
for: 5m
labels:
severity: critical
annotations:
summary: "Заканчивается место на OPNsense (/)"
description: "Корневой раздел / на OPNsense заполнен более чем на 95%."
- alert: OpnsenseHighCpuLoad
expr: opnsense_cpu_usage_percent > 90
for: 10m
labels:
severity: warning
annotations:
summary: "Высокая нагрузка CPU на OPNsense"
description: "Утилизация CPU на OPNsense превышает 90% более 10 минут."
- alert: OpnsenseHighMemoryUsage
expr: (opnsense_memory_used_bytes / opnsense_memory_total_bytes) * 100 > 90
for: 10m
labels:
severity: warning
annotations:
summary: "Мало оперативной памяти на OPNsense"
description: "Использование RAM на OPNsense превышает 90% более 10 минут."
[% endif %]
@@ -0,0 +1,158 @@
name: monitoring
services:
alertmanager:
image: prom/alertmanager:v0.28.1
container_name: monitoring-alertmanager
restart: unless-stopped
command:
- "--config.file=/etc/alertmanager/alertmanager.yml"
- "--storage.path=/alertmanager"
volumes:
- ./alertmanager:/etc/alertmanager:ro
- ./alertmanager_data:/alertmanager
ports:
- "9093:9093"
ntfy:
image: binwiederhier/ntfy:v2.11.0
container_name: monitoring-ntfy
restart: unless-stopped
command:
- "serve"
environment:
- NTFY_BASE_URL={{ ntfy_base_url }}
- NTFY_BEHIND_PROXY=true
- NTFY_AUTH_FILE=/var/cache/ntfy/auth.db
- NTFY_AUTH_DEFAULT_ACCESS=deny-all
- NTFY_ENABLE_LOGIN=true
- NTFY_CACHE_FILE=/var/cache/ntfy/cache.db
- NTFY_ATTACHMENT_CACHE_DIR=/var/cache/ntfy/attachments
volumes:
- ./ntfy_data:/var/cache/ntfy
ports:
- "80:80"
alertmanager-ntfy:
image: ghcr.io/alexbakker/alertmanager-ntfy:latest
container_name: monitoring-alertmanager-ntfy
restart: unless-stopped
command:
- "--configs=/etc/alertmanager-ntfy/config.yml"
volumes:
- ./alertmanager-ntfy:/etc/alertmanager-ntfy:ro
depends_on:
- ntfy
grafana:
image: grafana/grafana:11.5.2
container_name: monitoring-grafana
restart: unless-stopped
environment:
- GF_SECURITY_ADMIN_USER={{ grafana_admin_user }}
- GF_SECURITY_ADMIN_PASSWORD={{ grafana_admin_password }}
- GF_USERS_ALLOW_SIGN_UP=false
- GF_SERVER_ROOT_URL={{ grafana_root_url }}
volumes:
- ./grafana_data:/var/lib/grafana
- ./grafana/provisioning:/etc/grafana/provisioning:ro
ports:
- "3000:3000"
depends_on:
- vmsingle
vmsingle:
image: {{ victoriametrics_image }}
container_name: monitoring-vmsingle
hostname: vmsingle
restart: unless-stopped
command:
- --storageDataPath=/victoria-metrics-data
- --retentionPeriod={{ victoriametrics_retention }}
volumes:
- ./victoria-metrics-data:/victoria-metrics-data
ports:
- "{{ ansible_host }}:8428:8428"
cadvisor:
image: {{ cadvisor_image }}
container_name: monitoring-cadvisor
restart: unless-stopped
privileged: true
command:
- --listen_ip=0.0.0.0
- --port=9101
- --docker_only=true
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker:/var/lib/docker:ro
- /dev/disk:/dev/disk:ro
ports:
- "127.0.0.1:9101:9101"
{% if xray_checker_subscription_url | length > 0 %}
xray-checker:
image: {{ xray_checker_image }}
container_name: monitoring-xray-checker
hostname: xraychecker
restart: unless-stopped
env_file:
- ./xray-checker.env
ports:
- "127.0.0.1:2112:2112"
{% endif %}
{% if opnsense_exporter_enabled | bool %}
opnsense-exporter:
image: {{ opnsense_exporter_image }}
container_name: monitoring-opnsense-exporter
restart: unless-stopped
command: ["python3", "/app/exporter.py"]
env_file:
- ./opnsense-exporter.env
volumes:
- ./opnsense-exporter/exporter.py:/app/exporter.py:ro
ports:
- "127.0.0.1:9105:9105"
{% endif %}
vmagent:
image: {{ vmagent_image }}
container_name: monitoring-vmagent
restart: unless-stopped
command:
- -httpListenAddr=0.0.0.0:8429
- -promscrape.config=/etc/vmagent/scrape.yml
- -promscrape.configCheckInterval=60s
- -remoteWrite.url=http://vmsingle:8428/api/v1/write
volumes:
- ./vmagent/scrape.yml:/etc/vmagent/scrape.yml:ro
- ./vmagent/conf.d:/etc/vmagent/conf.d:ro
ports:
- "127.0.0.1:8429:8429"
depends_on:
- vmsingle
- cadvisor
vmalert:
image: {{ vmalert_image }}
container_name: monitoring-vmalert
restart: unless-stopped
command:
- -datasource.url=http://vmsingle:8428
- -notifier.url=http://alertmanager:9093
- -rule=/etc/vmalert/alerts.yml
- -evaluationInterval=15s
- -configCheckInterval=30s
- -httpListenAddr=0.0.0.0:8880
volumes:
- ./vmalert:/etc/vmalert:ro
ports:
- "127.0.0.1:8880:8880"
depends_on:
- vmsingle
- alertmanager
@@ -0,0 +1,12 @@
apiVersion: 1
providers:
- name: 'default'
orgId: 1
folder: 'Homelab'
type: file
disableDeletion: false
editable: true
updateIntervalSeconds: 10
options:
path: /etc/grafana/provisioning/dashboards
@@ -0,0 +1,21 @@
apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus
type: prometheus
access: proxy
url: http://vmsingle:8428
isDefault: false
jsonData:
timeInterval: 15s
- name: VictoriaMetrics
uid: victoriametrics
type: prometheus
access: proxy
url: http://vmsingle:8428
isDefault: true
jsonData:
timeInterval: 15s
@@ -0,0 +1,6 @@
OPNSENSE_API_URL={{ opnsense_api_url }}
OPNSENSE_API_KEY={{ opnsense_api_key }}
OPNSENSE_API_SECRET={{ opnsense_api_secret }}
OPNSENSE_VERIFY_TLS=false
OPNSENSE_EXPORTER_PORT=9105
@@ -0,0 +1,13 @@
- job_name: integrations/cAdvisor
scrape_interval: 15s
static_configs:
- targets: ["cadvisor:9101"]
labels:
instance: "{{ inventory_hostname }}"
cluster: "{{ vmagent_cluster }}"
{% for host in monitoring_cadvisor_scrape_hosts %}
- targets: ["{{ hostvars[host].ansible_host }}:{{ monitoring_cadvisor_port }}"]
labels:
instance: "{{ host }}"
cluster: "{{ vmagent_cluster }}"
{% endfor %}
@@ -0,0 +1,14 @@
- job_name: integrations/node_exporter
scrape_interval: 15s
static_configs:
- targets: ["{{ ansible_host }}:9100"]
labels:
instance: "{{ inventory_hostname }}"
cluster: "{{ vmagent_cluster }}"
{% for target in monitoring_scrape_targets if target.name not in vmagent_central_scrape_skip %}
- targets: ["{{ target.address }}:{{ target.port }}"]
labels:
instance: "{{ target.name }}"
cluster: "{{ vmagent_cluster }}"
host: "{{ target.name }}"
{% endfor %}
@@ -0,0 +1,9 @@
- job_name: opnsense
scrape_interval: 15s
static_configs:
- targets: ["opnsense-exporter:9105"]
labels:
instance: "opnsense"
cluster: "{{ vmagent_cluster }}"
host: "opnsense"
@@ -0,0 +1,5 @@
scrape_config_files:
- "/etc/vmagent/conf.d/*.yml"
global:
scrape_interval: 15s
@@ -0,0 +1,12 @@
- job_name: xray_checker
scrape_interval: 15s
static_configs:
- targets: ["xray-checker:2112"]
labels:
instance: "{{ inventory_hostname }}"
cluster: "{{ vmagent_cluster }}"
metric_relabel_configs:
- source_labels: [address]
regex: "yali\\.gunis\\.top:443"
target_label: name
replacement: "🇩🇪 ger-nod-02"
@@ -0,0 +1,4 @@
SUBSCRIPTION_URL={{ xray_checker_subscription_url }}
PROXY_CHECK_METHOD=status
PROXY_STATUS_CHECK_URL=http://google.com/generate_204
PROXY_CHECK_INTERVAL=60
@@ -0,0 +1,8 @@
---
authentik_version: "2024.12.3"
authentik_dir: "/opt/authentik"
authentik_enabled: false
authentik_http_port: 9000
authentik_secret_key: "{{ lookup('env', 'AUTHENTIK_SECRET_KEY') }}"
authentik_postgres_password: "{{ lookup('env', 'AUTHENTIK_POSTGRES_PASSWORD') }}"
@@ -0,0 +1,39 @@
# yaml-language-server: $schema=https://goauthentik.io/blueprints/schema.json
# Каталог пользователей. Пароли не задаются: их выставляет суперадмин в интерфейсе.
version: 1
metadata:
name: homelab-directory
labels:
blueprints.goauthentik.io/description: "Группы admins и family"
entries:
- model: authentik_core.group
id: admins
identifiers:
name: admins
- model: authentik_core.group
id: family
identifiers:
name: family
- model: authentik_core.user
identifiers:
username: karpenok
attrs:
name: karpenok
is_active: true
is_superuser: true
groups:
- !Find [authentik_core.group, [name, "authentik Admins"]]
- !KeyOf admins
- !KeyOf family
- model: authentik_core.user
identifiers:
username: ksynia
attrs:
name: ksynia
is_active: true
is_superuser: false
groups:
- !KeyOf family
@@ -0,0 +1,49 @@
# yaml-language-server: $schema=https://goauthentik.io/blueprints/schema.json
version: 1
metadata:
name: traefik-dashboard
labels:
blueprints.goauthentik.io/description: "Панель Traefik только для группы admins"
entries:
- model: authentik_core.group
id: group-admins
identifiers:
name: admins
- model: authentik_providers_proxy.proxyprovider
id: provider-traefik-dashboard
identifiers:
name: traefik-dashboard
attrs:
mode: forward_single
external_host: https://proxy.gunihome.ru
authorization_flow: !Find [authentik_flows.flow, [slug, default-provider-authorization-implicit-consent]]
invalidation_flow: !Find [authentik_flows.flow, [slug, default-provider-invalidation-flow]]
- model: authentik_core.application
id: app-traefik-dashboard
identifiers:
slug: traefik-dashboard
attrs:
name: Traefik
meta_launch_url: https://proxy.gunihome.ru
policy_engine_mode: any
provider: !KeyOf provider-traefik-dashboard
- model: authentik_policies.policybinding
identifiers:
order: 0
target: !KeyOf app-traefik-dashboard
attrs:
group: !KeyOf group-admins
- model: authentik_outposts.outpost
identifiers:
name: authentik Embedded Outpost
attrs:
type: proxy
service_connection: null
config:
authentik_host: https://auth.gunihome.ru
providers:
- !KeyOf provider-traefik-dashboard
@@ -0,0 +1,75 @@
---
- name: Остановить Authentik если сервис отключен
when: not (authentik_enabled | bool)
block:
- name: Проверить наличие compose.yaml для Authentik
ansible.builtin.stat:
path: "{{ authentik_dir }}/compose.yaml"
register: authentik_compose_stat
- name: Остановить контейнеры Authentik
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml stop
when: authentik_compose_stat.stat.exists
register: compose_stop
changed_when: "'Stopping' in compose_stop.stderr or 'Stopped' in compose_stop.stderr"
failed_when: false
- name: Управление сервисом Authentik
when: authentik_enabled | bool
block:
- name: Создать каталоги для сервиса Authentik с корректными правами
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
loop:
- { path: "{{ authentik_dir }}", owner: "root", group: "root", mode: "0755" }
- { path: "{{ authentik_dir }}/db", owner: "70", group: "70", mode: "0700" }
- { path: "{{ authentik_dir }}/redis", owner: "999", group: "999", mode: "0700" }
- { path: "{{ authentik_dir }}/media", owner: "1000", group: "1000", mode: "0775" }
- { path: "{{ authentik_dir }}/custom-templates", owner: "1000", group: "1000", mode: "0775" }
- { path: "{{ authentik_dir }}/blueprints", owner: "root", group: "root", mode: "0755" }
- name: Проверить наличие обязательных секретов Authentik
ansible.builtin.assert:
that:
- authentik_secret_key is defined and authentik_secret_key | length > 0
- authentik_postgres_password is defined and authentik_postgres_password | length > 0
fail_msg: "Один или несколько секретов Authentik (AUTHENTIK_SECRET_KEY, AUTHENTIK_POSTGRES_PASSWORD) не переданы!"
- name: Установить compose.yaml для Authentik
ansible.builtin.template:
src: compose.yaml.j2
dest: "{{ authentik_dir }}/compose.yaml"
owner: root
group: root
mode: "0600"
no_log: true
- name: Синхронизировать статические blueprints Authentik
ansible.builtin.copy:
src: blueprints/
dest: "{{ authentik_dir }}/blueprints/"
owner: root
group: root
mode: "0644"
register: authentik_blueprint
- name: Запустить сервисы Authentik через Docker Compose
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml up -d --remove-orphans
register: compose_up
changed_when: "'Started' in compose_up.stderr or 'Created' in compose_up.stderr or 'Recreated' in compose_up.stderr or 'Pulled' in compose_up.stderr"
- name: Перезапустить воркер Authentik при обновлении blueprints
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml restart authentik-worker
when: authentik_blueprint.changed and not compose_up.changed
- name: Применить blueprints Authentik в authentik-server
ansible.builtin.command: >
docker compose -f {{ authentik_dir }}/compose.yaml exec -T authentik-server
ak apply_blueprint /blueprints/custom/traefik-dashboard.yaml
when: authentik_blueprint.changed or compose_up.changed
register: apply_blueprints_cmd
changed_when: true
@@ -0,0 +1,96 @@
services:
authentik-db:
image: postgres:16-alpine
container_name: authentik-db
restart: unless-stopped
environment:
POSTGRES_PASSWORD: {{ authentik_postgres_password | to_json }}
POSTGRES_USER: authentik
POSTGRES_DB: authentik
volumes:
- {{ authentik_dir }}/db:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -d authentik -U authentik"]
interval: 5s
timeout: 5s
retries: 10
networks:
- authentik-net
authentik-redis:
image: redis:8-alpine
container_name: authentik-redis
restart: unless-stopped
volumes:
- {{ authentik_dir }}/redis:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 5s
retries: 10
networks:
- authentik-net
authentik-server:
image: ghcr.io/goauthentik/server:{{ authentik_version }}
container_name: authentik-server
restart: unless-stopped
command: server
environment:
AUTHENTIK_REDIS__HOST: authentik-redis
AUTHENTIK_POSTGRESQL__HOST: authentik-db
AUTHENTIK_POSTGRESQL__USER: authentik
AUTHENTIK_POSTGRESQL__NAME: authentik
AUTHENTIK_POSTGRESQL__PASSWORD: {{ authentik_postgres_password | to_json }}
AUTHENTIK_SECRET_KEY: {{ authentik_secret_key | to_json }}
AUTHENTIK_DISABLE_UPDATE_CHECK: "true"
AUTHENTIK_DISABLE_STARTUP_ANALYTICS: "true"
AUTHENTIK_ERROR_REPORTING__ENABLED: "false"
AUTHENTIK_OUTPOSTS__DISCOVER: "false"
volumes:
- {{ authentik_dir }}/media:/media
- {{ authentik_dir }}/custom-templates:/templates
- {{ authentik_dir }}/blueprints:/blueprints/custom:ro
ports:
- "127.0.0.1:{{ authentik_http_port }}:9000"
depends_on:
authentik-db:
condition: service_healthy
authentik-redis:
condition: service_healthy
networks:
- authentik-net
authentik-worker:
image: ghcr.io/goauthentik/server:{{ authentik_version }}
container_name: authentik-worker
restart: unless-stopped
command: worker
environment:
AUTHENTIK_REDIS__HOST: authentik-redis
AUTHENTIK_POSTGRESQL__HOST: authentik-db
AUTHENTIK_POSTGRESQL__USER: authentik
AUTHENTIK_POSTGRESQL__NAME: authentik
AUTHENTIK_POSTGRESQL__PASSWORD: {{ authentik_postgres_password | to_json }}
AUTHENTIK_SECRET_KEY: {{ authentik_secret_key | to_json }}
AUTHENTIK_DISABLE_UPDATE_CHECK: "true"
AUTHENTIK_DISABLE_STARTUP_ANALYTICS: "true"
AUTHENTIK_ERROR_REPORTING__ENABLED: "false"
AUTHENTIK_OUTPOSTS__DISCOVER: "false"
volumes:
- {{ authentik_dir }}/media:/media
- {{ authentik_dir }}/custom-templates:/templates
- {{ authentik_dir }}/blueprints:/blueprints/custom:ro
depends_on:
authentik-db:
condition: service_healthy
authentik-redis:
condition: service_healthy
networks:
- authentik-net
networks:
authentik-net:
name: authentik-net
driver: bridge
@@ -0,0 +1,4 @@
---
- name: Клиент NetBird на панели
ansible.builtin.include_role:
name: netbird_client
@@ -0,0 +1,36 @@
---
remnawave_dir: /opt/remnawave
remnawave_subscription_dir: "{{ remnawave_dir }}/subscription"
remnawave_panel_domain: "rw.gunihome.ru"
remnawave_sub_domain: "sub.gunihome.ru"
remnawave_panel_url: "https://{{ remnawave_panel_domain }}"
remnawave_backend_image: "remnawave/backend:3"
remnawave_subscription_image: "remnawave/subscription-page:latest"
remnawave_postgres_image: "postgres:18.4"
remnawave_redis_image: "valkey/valkey:9-alpine"
remnawave_app_port: 3000
remnawave_metrics_port: 3001
remnawave_subscription_port: 3010
# Логин панели: отдельный от /USER/ADMIN — Remnawave v3 требует пароль ≥24
# с upper+lower+digit. Хранится в Infisical /services/remnawave.
remnawave_admin_username: "{{ lookup('env', 'REMNAWAVE_ADMIN_USER', default=lookup('env', 'ADMIN_USER', default='karpenok')) }}"
remnawave_admin_password: "{{ lookup('env', 'REMNAWAVE_ADMIN_PASSWORD', default='') }}"
remnawave_app_secret: "{{ lookup('env', 'REMNAWAVE_APP_SECRET', default='') }}"
remnawave_postgres_password: "{{ lookup('env', 'REMNAWAVE_POSTGRES_PASSWORD', default='') }}"
remnawave_metrics_pass: "{{ lookup('env', 'REMNAWAVE_METRICS_PASS', default='') }}"
remnawave_webhook_secret: "{{ lookup('env', 'REMNAWAVE_WEBHOOK_SECRET_HEADER', default='') }}"
remnawave_api_token: "{{ lookup('env', 'REMNAWAVE_API_TOKEN', default='') }}"
remnawave_netbird_peers_url: "https://central.gunihome.ru/api/peers"
remnawave_xray_checker_user: "homelab"
remnawave_api_token_name: "infra-automation"
# Документация WAN egress панели (см. remnanode_panel_egress_ips на выходных нодах).
remnawave_panel_egress_ips:
- "213.128.28.107" # провайдер 1 (МТС)
- "185.160.137.140" # провайдер 2
@@ -0,0 +1,22 @@
# Декларативная конфигурация профилей, нод и хостов Remnawave.
# Добавление новой выходной VPS: добавить запись в nodes и прогнать ansible-core-net.
xray_template:
name: Except-RU
file: xray-except-ru.json
squad_name: Default-Squad
subscription_page_config: Homelab
nodes:
- name: Ger-nod-02
address: "150.241.64.209"
netbird_hostname: "ger-nod-02"
port: 2222
country_code: "DE"
profile_name: "DE-Yali"
profile_template: "profile-selfsteal-xhttp.json"
inbound_tag: "Steal-Yali"
selfsteal_domain: "yali.gunis.top"
xhttp_path: "/xhttp-yali"
host_remark: "🇩🇪 ger-nod-02"
@@ -0,0 +1,161 @@
{
"log": {
"loglevel": "warning"
},
"dns": {
"servers": [
{
"address": "https://dns.google/dns-query",
"skipFallback": false
}
],
"queryStrategy": "UseIPv4"
},
"inbounds": [
{
"tag": "__INBOUND_TAG__",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [],
"decryption": "none"
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls", "quic"]
},
"streamSettings": {
"network": "xhttp",
"security": "reality",
"xhttpSettings": {
"host": "__SELFSTEAL_DOMAIN__",
"mode": "stream-one",
"path": "__XHTTP_PATH__"
},
"realitySettings": {
"dest": "/dev/shm/nginx.sock",
"show": false,
"xver": 1,
"spiderX": "",
"shortIds": ["__REALITY_SHORT_ID__"],
"privateKey": "__REALITY_PRIVATE_KEY__",
"serverNames": ["__SELFSTEAL_DOMAIN__"]
}
}
}
],
"outbounds": [
{
"tag": "DIRECT",
"protocol": "freedom"
},
{
"tag": "BLOCK",
"protocol": "blackhole"
}
],
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
"domain": [
"regexp:^([a-z0-9-]+\\.)*2ip\\.[a-z0-9.-]+$",
"domain:ifconfig.me",
"domain:www.ifconfig.me",
"domain:ifconfig.co",
"domain:www.ifconfig.co",
"domain:ifconfig.io",
"domain:www.ifconfig.io",
"domain:ifconfig.so",
"domain:checkip.amazonaws.com",
"domain:api.ipify.org",
"domain:ipify.org",
"domain:ip.sb",
"domain:www.ip.sb",
"domain:api-ipv4.ip.sb",
"domain:api.ipv6.ip.sb",
"domain:ip-api.com",
"domain:api.ipapi.is",
"domain:ipapi.co",
"domain:ipapi.com",
"domain:iplocation.net",
"domain:iplocation.io",
"domain:iplocation.com",
"domain:ipwho.is",
"domain:ipwhois.io",
"domain:ipinfo.io",
"domain:www.ipinfo.io",
"domain:ident.me",
"domain:myip.com",
"domain:whatismyipaddress.com",
"domain:wtfismyip.com",
"domain:whatismyip.com",
"domain:showmyip.com",
"domain:icanhazip.com",
"domain:geojs.io",
"domain:ipleak.net",
"domain:ipleak.org",
"domain:browserleaks.com",
"domain:dnsleaktest.com",
"domain:dnscheck.tools",
"domain:whoer.net",
"domain:hidemy.name",
"domain:sypexgeo.net",
"domain:api.sypexgeo.net",
"domain:mail.ru",
"domain:ip.mail.ru",
"full:ipv4-internet.yandex.net",
"full:ipv6-internet.yandex.net",
"full:www.cloudflare.com/cdn-cgi/trace"
],
"outboundTag": "BLOCK"
},
{
"type": "field",
"domain": [
"domain:habr.com",
"domain:4pda.to",
"domain:4pda.ru",
"domain:kemono.su",
"domain:jut.su",
"domain:kara.su",
"domain:theins.ru",
"domain:tvrain.ru",
"domain:echo.msk.ru",
"domain:the-village.ru",
"domain:snob.ru",
"domain:novayagazeta.ru",
"domain:moscowtimes.ru",
"domain:allnorilsk.ru"
],
"outboundTag": "DIRECT"
},
{
"type": "field",
"ip": ["geoip:ru"],
"outboundTag": "BLOCK"
},
{
"type": "field",
"domain": ["geosite:category-ru"],
"outboundTag": "BLOCK"
},
{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "BLOCK"
},
{
"type": "field",
"protocol": ["bittorrent"],
"outboundTag": "BLOCK"
},
{
"type": "field",
"network": "tcp,udp",
"outboundTag": "DIRECT"
}
]
}
}
@@ -0,0 +1,631 @@
#!/usr/bin/env python3
"""Идемпотентная синхронизация шаблонов, профилей, нод, хостов, сквадов и пользователей Remnawave."""
from __future__ import annotations
import json
import os
import re
import secrets
import subprocess
import sys
from typing import Any
def _redact_text(text: str) -> str:
"""Убирает потенциально чувствительные поля при выводе ошибок."""
return re.sub(
r'("(?:privateKey|privKey|secretKey|accessToken|apiToken|password|token|vlessUuid|trojanPassword|ssPassword|shortUuid)"\s*:\s*)"[^"]*"',
r'\1"[REDACTED]"',
text,
flags=re.IGNORECASE,
)
class RemnawaveAPI:
"""Минимальный клиент Remnawave API через curl с --resolve на 127.0.0.1."""
def __init__(self, domain: str, token: str) -> None:
self.domain = domain
self.base_url = f"https://{domain}/api"
self.token = token
def request(
self,
method: str,
path: str,
payload: dict[str, Any] | None = None,
allow_error: bool = False,
) -> tuple[int, Any]:
cmd = [
"curl",
"-sSk",
"--resolve",
f"{self.domain}:443:127.0.0.1",
"-w",
"\n%{http_code}",
"-X",
method,
f"{self.base_url}{path}",
"-H",
"X-Remnawave-Client-Type: browser",
"-H",
f"Authorization: Bearer {self.token}",
]
stdin_bytes = None
if payload is not None:
cmd.extend(["-H", "Content-Type: application/json", "--data-binary", "@-"])
stdin_bytes = json.dumps(payload, ensure_ascii=False).encode("utf-8")
proc = subprocess.run(cmd, input=stdin_bytes, capture_output=True, check=False)
if proc.returncode != 0:
raise RuntimeError(
f"curl error for {method} {path}: {proc.stderr.decode(errors='replace')}"
)
raw = proc.stdout.decode("utf-8", errors="replace")
body, _, code_str = raw.rpartition("\n")
status = int(code_str.strip() or "0")
data: Any = None
if body.strip():
try:
data = json.loads(body)
except json.JSONDecodeError:
data = body
if not (200 <= status < 300):
if allow_error:
return status, data
raise RuntimeError(
f"Remnawave API {method} {path} failed (HTTP {status}): {_redact_text(body)}"
)
return status, data
def resolve_netbird_peers(peers_url: str, nb_token: str) -> dict[str, str]:
"""Возвращает карту hostname/name/dns_label -> IPv4 из NetBird API."""
if not peers_url or not nb_token:
return {}
cmd = [
"curl",
"-fsS",
"--max-time",
"20",
"-H",
f"Authorization: Token {nb_token}",
peers_url,
]
proc = subprocess.run(cmd, capture_output=True, check=False)
if proc.returncode != 0:
return {}
try:
raw = json.loads(proc.stdout.decode("utf-8", errors="replace"))
except json.JSONDecodeError:
return {}
peers = raw if isinstance(raw, list) else (raw.get("items") or raw.get("peers") or [])
mapping: dict[str, str] = {}
ip_re = re.compile(r"^\d+\.\d+\.\d+\.\d+$")
for peer in peers:
if not isinstance(peer, dict):
continue
ip = str(peer.get("ip") or "").strip()
if not ip_re.match(ip):
continue
for key in ("hostname", "name", "dns_label"):
val = str(peer.get(key) or "").strip()
if val and val not in mapping:
mapping[val] = ip
return mapping
def _norm_iso(val: str | None) -> str:
if not val:
return ""
return val.replace(".000Z", "Z")
def _extract_list(resp: Any, *keys: str) -> list[dict[str, Any]]:
if isinstance(resp, dict):
inner = resp.get("response", resp)
if isinstance(inner, list):
return inner
if isinstance(inner, dict):
for k in keys:
if isinstance(inner.get(k), list):
return inner[k]
if isinstance(resp, list):
return resp
return []
def sync_xray_template(
api: RemnawaveAPI,
tpl_name: str,
tpl_json: dict[str, Any],
changes: list[str],
) -> str:
_, tpl_list = api.request("GET", "/subscription-templates/")
templates = _extract_list(tpl_list, "templates")
tpl_uuid = next(
(
t["uuid"]
for t in templates
if t.get("name") == tpl_name and t.get("templateType") == "XRAY_JSON"
),
"",
)
if not tpl_uuid:
_, created = api.request(
"POST",
"/subscription-templates/",
{"name": tpl_name, "templateType": "XRAY_JSON", "templateJson": tpl_json},
)
tpl_uuid = (created.get("response") or created).get("uuid", "")
if not tpl_uuid:
raise RuntimeError(f"Не удалось создать шаблон {tpl_name}")
changes.append(f"created xray template {tpl_name}")
else:
_, tpl_full = api.request("GET", f"/subscription-templates/{tpl_uuid}")
current = (tpl_full.get("response") or {}).get("templateJson") or {}
if current != tpl_json:
api.request(
"PATCH",
"/subscription-templates/",
{"uuid": tpl_uuid, "templateJson": tpl_json},
)
changes.append(f"updated xray template {tpl_name}")
return tpl_uuid
def ensure_profile_and_inbound(
api: RemnawaveAPI,
node_cfg: dict[str, Any],
profile_templates: dict[str, str],
changes: list[str],
) -> tuple[str, str]:
profile_name = node_cfg["profile_name"]
inbound_tag = node_cfg["inbound_tag"]
_, profiles_resp = api.request("GET", "/config-profiles/")
profiles = _extract_list(profiles_resp, "configProfiles")
profile_uuid = next((p["uuid"] for p in profiles if p.get("name") == profile_name), "")
if not profile_uuid:
tpl_key = node_cfg["profile_template"]
raw_tpl = profile_templates.get(tpl_key)
if not raw_tpl:
raise RuntimeError(f"Не найден шаблон профиля {tpl_key}")
_, key_resp = api.request("GET", "/system/tools/x25519/generate")
resp_obj = key_resp.get("response") or key_resp
keypairs = resp_obj.get("keypairs") or []
priv = (
(keypairs[0].get("privateKey") if keypairs else None)
or resp_obj.get("privateKey")
or resp_obj.get("privKey")
or ""
)
if not priv:
raise RuntimeError("Не удалось сгенерировать X25519 ключ Reality")
short_id = secrets.token_hex(8)
rendered = (
raw_tpl.replace("__REALITY_PRIVATE_KEY__", priv)
.replace("__REALITY_SHORT_ID__", short_id)
.replace("__INBOUND_TAG__", inbound_tag)
.replace("__SELFSTEAL_DOMAIN__", node_cfg["selfsteal_domain"])
.replace("__XHTTP_PATH__", node_cfg["xhttp_path"])
)
_, created = api.request(
"POST",
"/config-profiles/",
{"name": profile_name, "config": json.loads(rendered)},
)
profile_uuid = (created.get("response") or created).get("uuid", "")
if not profile_uuid:
raise RuntimeError(f"Не удалось создать config profile {profile_name}")
changes.append(f"created profile {profile_name}")
_, profile_full = api.request("GET", f"/config-profiles/{profile_uuid}")
inbounds = _extract_list(profile_full, "inbounds")
if not inbounds:
_, inb_resp = api.request("GET", f"/config-profiles/{profile_uuid}/inbounds")
inbounds = _extract_list(inb_resp, "inbounds")
inbound_uuid = next((i["uuid"] for i in inbounds if i.get("tag") == inbound_tag), "")
if not inbound_uuid:
raise RuntimeError(f"Не найден inbound {inbound_tag} в профиле {profile_uuid}")
return profile_uuid, inbound_uuid
def sync_node_and_host(
api: RemnawaveAPI,
node_cfg: dict[str, Any],
profile_uuid: str,
inbound_uuid: str,
tpl_uuid: str,
nb_peers: dict[str, str],
netbird_connected: bool,
changes: list[str],
warnings: list[str],
) -> None:
node_name = node_cfg["name"]
target_addr = node_cfg["address"]
nb_host = node_cfg.get("netbird_hostname", "")
if netbird_connected and nb_host and nb_host in nb_peers:
target_addr = nb_peers[nb_host]
elif nb_host:
warnings.append(
f"node {node_name}: используется fallback-адрес {target_addr} (NetBird peer {nb_host} недоступен)"
)
_, nodes_resp = api.request("GET", "/nodes/")
nodes = _extract_list(nodes_resp)
existing_node = next((n for n in nodes if n.get("name") == node_name), None)
desired_cp = {
"activeConfigProfileUuid": profile_uuid,
"activeInbounds": [inbound_uuid],
}
if not existing_node:
_, created = api.request(
"POST",
"/nodes/",
{
"name": node_name,
"address": target_addr,
"port": int(node_cfg["port"]),
"countryCode": node_cfg["country_code"],
"configProfile": desired_cp,
},
)
node_uuid = (created.get("response") or created).get("uuid", "")
if not node_uuid:
raise RuntimeError(f"Не удалось создать ноду {node_name}")
changes.append(f"created node {node_name} ({target_addr})")
else:
node_uuid = existing_node["uuid"]
cur_cp = existing_node.get("configProfile") or {}
cur_inbounds = [
i["uuid"] if isinstance(i, dict) else i
for i in (cur_cp.get("activeInbounds") or [])
]
needs_update = (
existing_node.get("address") != target_addr
or int(existing_node.get("port") or 0) != int(node_cfg["port"])
or cur_cp.get("activeConfigProfileUuid") != profile_uuid
or cur_inbounds != [inbound_uuid]
)
if needs_update:
payload = {
"uuid": node_uuid,
"address": target_addr,
"port": int(node_cfg["port"]),
"configProfile": desired_cp,
}
code, _ = api.request("PATCH", "/nodes/", payload, allow_error=True)
if not (200 <= code < 300):
api.request("PUT", "/nodes/", payload)
changes.append(f"updated node {node_name} ({target_addr})")
selfsteal = node_cfg["selfsteal_domain"]
_, hosts_resp = api.request("GET", "/hosts/")
hosts = _extract_list(hosts_resp)
existing_host = next((h for h in hosts if h.get("address") == selfsteal), None)
if not existing_host:
host_payload = {
"remark": node_cfg["host_remark"],
"address": selfsteal,
"port": 443,
"path": node_cfg["xhttp_path"],
"sni": selfsteal,
"host": selfsteal,
"fingerprint": "chrome",
"isDisabled": False,
"securityLayer": "DEFAULT",
"alpn": "h2",
"xHttpExtraParams": {
"xmux": {
"maxConcurrency": "16-32",
"hMaxRequestTimes": "600-900",
"hMaxReusableSecs": "1800-3000",
},
"noSSEHeader": True,
"xPaddingBytes": "100-1000",
},
"inbound": {
"configProfileUuid": profile_uuid,
"configProfileInboundUuid": inbound_uuid,
},
"nodes": [node_uuid],
}
if tpl_uuid:
host_payload["xrayJsonTemplateUuid"] = tpl_uuid
_, created = api.request("POST", "/hosts/", host_payload)
host_uuid = (created.get("response") or created).get("uuid", "")
if not host_uuid:
raise RuntimeError(f"Не удалось создать host {selfsteal}")
changes.append(f"created host {selfsteal}")
else:
host_uuid = existing_host["uuid"]
patch_fields: dict[str, Any] = {"uuid": host_uuid}
if existing_host.get("remark") != node_cfg["host_remark"]:
patch_fields["remark"] = node_cfg["host_remark"]
if tpl_uuid and existing_host.get("xrayJsonTemplateUuid") != tpl_uuid:
patch_fields["xrayJsonTemplateUuid"] = tpl_uuid
if len(patch_fields) > 1:
api.request("PATCH", "/hosts/", patch_fields)
changes.append(f"updated host {selfsteal}")
def sync_squad(
api: RemnawaveAPI,
squad_name: str,
inbound_uuids: list[str],
changes: list[str],
) -> dict[str, str]:
_, squads_resp = api.request("GET", "/internal-squads/")
squads = _extract_list(squads_resp, "internalSquads")
squad_map = {s["name"]: s["uuid"] for s in squads if s.get("name") and s.get("uuid")}
target = next((s for s in squads if s.get("name") == squad_name), None)
if target:
cur_inbounds = [i["uuid"] for i in (target.get("inbounds") or []) if i.get("uuid")]
desired_inbounds = list(dict.fromkeys(inbound_uuids))
if set(cur_inbounds) != set(desired_inbounds):
api.request(
"PATCH",
"/internal-squads/",
{"uuid": target["uuid"], "inbounds": desired_inbounds},
)
changes.append(f"updated squad {squad_name} inbounds")
return squad_map
def cleanup_removed_nodes_and_hosts(
api: RemnawaveAPI,
desired_nodes: list[dict[str, Any]],
changes: list[str],
) -> None:
desired_domains = {n["selfsteal_domain"] for n in desired_nodes}
desired_node_names = {n["name"] for n in desired_nodes}
desired_profile_names = {n["profile_name"] for n in desired_nodes}
_, hosts_resp = api.request("GET", "/hosts/")
for h in _extract_list(hosts_resp):
if h.get("address") not in desired_domains and h.get("uuid"):
api.request("DELETE", f"/hosts/{h['uuid']}")
changes.append(f"deleted host {h.get('address')}")
_, nodes_resp = api.request("GET", "/nodes/")
for n in _extract_list(nodes_resp):
if n.get("name") not in desired_node_names and n.get("uuid"):
api.request("DELETE", f"/nodes/{n['uuid']}")
changes.append(f"deleted node {n.get('name')}")
_, profiles_resp = api.request("GET", "/config-profiles/")
for p in _extract_list(profiles_resp, "configProfiles"):
if p.get("name") not in desired_profile_names and p.get("uuid"):
api.request("DELETE", f"/config-profiles/{p['uuid']}")
changes.append(f"deleted profile {p.get('name')}")
def sync_subscription_settings(
api: RemnawaveAPI,
sub_page_cfg_name: str,
changes: list[str],
) -> None:
_, cfgs_resp = api.request("GET", "/subscription-page-configs/")
configs = _extract_list(cfgs_resp, "configs")
if not any(c.get("name") == sub_page_cfg_name for c in configs):
api.request("POST", "/subscription-page-configs/", {"name": sub_page_cfg_name})
changes.append(f"created subscription-page-config {sub_page_cfg_name}")
code, settings_resp = api.request("GET", "/subscription-settings/", allow_error=True)
if not (200 <= code < 300) or not isinstance(settings_resp, dict):
return
resp_obj = settings_resp.get("response") or settings_resp
browser_rule = {
"name": "Browser",
"enabled": True,
"operator": "OR",
"description": "IaC: HTML-страница подписки",
"responseType": "BROWSER",
"conditions": [
{"headerName": "accept", "operator": "CONTAINS", "value": "text/html", "caseSensitive": False},
{"headerName": "user-agent", "operator": "CONTAINS", "value": "Mozilla", "caseSensitive": False},
],
}
cur_rules = (resp_obj.get("responseRules") or {}).get("rules") or []
other_rules = [
r
for r in cur_rules
if r.get("name") not in ("Browser", "Browser Subscription")
and r.get("responseType") != "BROWSER"
]
desired_rules = [browser_rule] + other_rules
if (
resp_obj.get("serveJsonAtBaseSubscription") is True
and len(cur_rules) == len(desired_rules)
and cur_rules
and cur_rules[0].get("name") == "Browser"
and cur_rules[0].get("responseType") == "BROWSER"
and cur_rules[0].get("enabled") is True
):
return
patched = dict(resp_obj)
patched["serveJsonAtBaseSubscription"] = True
patched["responseRules"] = dict(resp_obj.get("responseRules") or {})
patched["responseRules"]["rules"] = desired_rules
pcode, _ = api.request("PATCH", "/subscription-settings/", patched, allow_error=True)
if not (200 <= pcode < 300):
api.request("PUT", "/subscription-settings/", patched)
changes.append("updated subscription-settings Browser rule")
def sync_users(
api: RemnawaveAPI,
desired_users: list[dict[str, Any]],
managed_tag: str,
squad_map: dict[str, str],
xray_checker_user: str,
sub_domain: str,
changes: list[str],
) -> str:
if not re.match(r"^[A-Z0-9_]{1,16}$", managed_tag):
raise RuntimeError(f"Некорректный managed_tag '{managed_tag}' (допустимо ^[A-Z0-9_]{{1,16}}$)")
code, users_resp = api.request("GET", "/users/?size=500", allow_error=True)
if not (200 <= code < 300):
_, users_resp = api.request("GET", "/users/")
existing_users = _extract_list(users_resp, "users")
by_name = {u["username"]: u for u in existing_users if u.get("username")}
desired_names: set[str] = set()
mutated = False
for u in desired_users:
uname = u["username"]
desired_names.add(uname)
squad_name = u.get("squad", "Default-Squad")
sid = squad_map.get(squad_name, "")
want_squads = [sid] if sid else []
want_tag = u.get("tag") or managed_tag
want_body = {
"username": uname,
"status": u.get("status", "ACTIVE"),
"expireAt": u["expire_at"],
"description": u.get("description", ""),
"trafficLimitBytes": int(u.get("traffic_limit_bytes", 0)),
"trafficLimitStrategy": u.get("traffic_limit_strategy", "NO_RESET"),
"activeInternalSquads": want_squads,
"tag": want_tag,
}
cur = by_name.get(uname)
if not cur:
api.request("POST", "/users/", want_body)
changes.append(f"created user {uname}")
mutated = True
else:
cur_squads = [
s["uuid"] if isinstance(s, dict) else s
for s in (cur.get("activeInternalSquads") or [])
]
differs = (
cur.get("status") != want_body["status"]
or _norm_iso(cur.get("expireAt")) != _norm_iso(want_body["expireAt"])
or (cur.get("description") or "") != want_body["description"]
or int(cur.get("trafficLimitBytes") or 0) != want_body["trafficLimitBytes"]
or cur.get("trafficLimitStrategy") != want_body["trafficLimitStrategy"]
or cur_squads != want_squads
or (cur.get("tag") or "") != want_tag
)
if differs:
patch_body = {**want_body, "uuid": cur["uuid"]} if cur.get("uuid") else want_body
api.request("PATCH", "/users/", patch_body)
changes.append(f"updated user {uname}")
mutated = True
for uname, cur in by_name.items():
if uname not in desired_names and (cur.get("tag") or "") == managed_tag:
uid = cur.get("uuid") or cur.get("id")
api.request("DELETE", f"/users/{uid}")
changes.append(f"deleted user {uname}")
mutated = True
if mutated:
_, users_resp = api.request("GET", "/users/?size=500")
existing_users = _extract_list(users_resp, "users")
by_name = {u["username"]: u for u in existing_users if u.get("username")}
xray_url = ""
if xray_checker_user and xray_checker_user in by_name:
uobj = by_name[xray_checker_user]
xray_url = uobj.get("subscriptionUrl") or ""
if not xray_url and uobj.get("shortUuid") and sub_domain:
xray_url = f"https://{sub_domain}/{uobj['shortUuid']}"
return xray_url
def main() -> int:
if len(sys.argv) != 2:
print("Usage: sync_remnawave.py <sync_config.json>", file=sys.stderr)
return 2
with open(sys.argv[1], "r", encoding="utf-8") as fh:
cfg = json.load(fh)
token = os.environ.get("RW_API_TOKEN", "").strip()
if not token:
print("RW_API_TOKEN is required", file=sys.stderr)
return 1
api = RemnawaveAPI(cfg["panel_domain"], token)
changes: list[str] = []
warnings: list[str] = []
nb_peers = {}
if cfg.get("netbird_connected"):
nb_peers = resolve_netbird_peers(
cfg.get("netbird_peers_url", ""),
os.environ.get("NB_API_TOKEN", "").strip(),
)
tpl_uuid = sync_xray_template(
api,
cfg["xray_template"]["name"],
cfg["xray_template_json"],
changes,
)
inbound_uuids: list[str] = []
for node_cfg in cfg.get("nodes", []):
profile_uuid, inbound_uuid = ensure_profile_and_inbound(
api, node_cfg, cfg.get("profile_templates", {}), changes
)
inbound_uuids.append(inbound_uuid)
sync_node_and_host(
api,
node_cfg,
profile_uuid,
inbound_uuid,
tpl_uuid,
nb_peers,
bool(cfg.get("netbird_connected")),
changes,
warnings,
)
squad_map = sync_squad(api, cfg.get("squad_name", "Default-Squad"), inbound_uuids, changes)
cleanup_removed_nodes_and_hosts(api, cfg.get("nodes", []), changes)
sync_subscription_settings(api, cfg.get("subscription_page_config", "Homelab"), changes)
xray_url = sync_users(
api,
cfg.get("users", []),
cfg.get("managed_tag", "IAC"),
squad_map,
cfg.get("xray_checker_user", "homelab"),
cfg.get("sub_domain", ""),
changes,
)
result = {
"changed": len(changes) > 0,
"changes": changes,
"warnings": warnings,
"xray_checker_subscription_url": xray_url,
}
print(json.dumps(result, ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())
@@ -0,0 +1,14 @@
# Источник правды для системных/админских пользователей Remnawave.
# Пользователи с tag: IAC полностью управляются из Git (создаются, обновляются и удаляются).
# Динамические пользователи (например, из Telegram-бота с другим тегом или без тега) не трогаются.
# Пароли/UUID генерирует панель; в файл их не класть.
managed_tag: IAC
users:
- username: homelab
status: ACTIVE
expire_at: "2099-01-01T00:00:00.000Z"
description: homelab
traffic_limit_bytes: 0
traffic_limit_strategy: NO_RESET
squad: Default-Squad
@@ -0,0 +1,156 @@
{
"remnawave": {
"addVirtualHostAsOutbound": true
},
"routing": {
"rules": [
{
"type": "field",
"domain": [
"regexp:^([a-z0-9-]+\\.)*2ip\\.[a-z0-9.-]+$",
"domain:ifconfig.me",
"domain:www.ifconfig.me",
"domain:ifconfig.co",
"domain:www.ifconfig.co",
"domain:ifconfig.io",
"domain:www.ifconfig.io",
"domain:ifconfig.so",
"domain:checkip.amazonaws.com",
"domain:api.ipify.org",
"domain:ipify.org",
"domain:ip.sb",
"domain:www.ip.sb",
"domain:api-ipv4.ip.sb",
"domain:api.ipv6.ip.sb",
"domain:ip-api.com",
"domain:api.ipapi.is",
"domain:ipapi.co",
"domain:ipapi.com",
"domain:iplocation.net",
"domain:iplocation.io",
"domain:iplocation.com",
"domain:ipwho.is",
"domain:ipwhois.io",
"domain:ipinfo.io",
"domain:www.ipinfo.io",
"domain:ident.me",
"domain:myip.com",
"domain:whatismyipaddress.com",
"domain:wtfismyip.com",
"domain:whatismyip.com",
"domain:showmyip.com",
"domain:icanhazip.com",
"domain:geojs.io",
"domain:ipleak.net",
"domain:ipleak.org",
"domain:browserleaks.com",
"domain:dnsleaktest.com",
"domain:dnscheck.tools",
"domain:whoer.net",
"domain:hidemy.name",
"domain:sypexgeo.net",
"domain:api.sypexgeo.net",
"domain:mail.ru",
"domain:ip.mail.ru",
"full:ipv4-internet.yandex.net",
"full:ipv6-internet.yandex.net",
"full:www.cloudflare.com/cdn-cgi/trace"
],
"outboundTag": "direct"
},
{
"type": "field",
"domain": ["domain:gunihome.ru"],
"outboundTag": "direct"
},
{
"type": "field",
"domain": [
"domain:habr.com",
"domain:4pda.to",
"domain:4pda.ru",
"domain:kemono.su",
"domain:jut.su",
"domain:kara.su",
"domain:theins.ru",
"domain:tvrain.ru",
"domain:echo.msk.ru",
"domain:the-village.ru",
"domain:snob.ru",
"domain:novayagazeta.ru",
"domain:moscowtimes.ru",
"domain:allnorilsk.ru"
],
"outboundTag": "proxy"
},
{
"ip": ["geoip:ru"],
"type": "field",
"outboundTag": "direct"
},
{
"type": "field",
"domain": ["geosite:category-ru"],
"outboundTag": "direct"
},
{
"ip": ["geoip:private"],
"type": "field",
"outboundTag": "direct"
},
{
"type": "field",
"protocol": ["bittorrent"],
"outboundTag": "direct"
},
{
"type": "field",
"network": "tcp,udp",
"outboundTag": "proxy"
}
],
"domainMatcher": "hybrid",
"domainStrategy": "IPIfNonMatch"
},
"inbounds": [
{
"tag": "socks",
"port": 10808,
"listen": "127.0.0.1",
"protocol": "socks",
"settings": {
"udp": true,
"auth": "noauth"
},
"sniffing": {
"enabled": true,
"routeOnly": false,
"destOverride": ["http", "tls", "quic"]
}
},
{
"tag": "http",
"port": 10809,
"listen": "127.0.0.1",
"protocol": "http",
"settings": {
"allowTransparent": false
},
"sniffing": {
"enabled": true,
"routeOnly": false,
"destOverride": ["http", "tls", "quic"]
}
}
],
"outbounds": [
{
"tag": "direct",
"protocol": "freedom"
},
{
"tag": "block",
"protocol": "blackhole"
}
]
}
@@ -0,0 +1,373 @@
---
- name: Проверить наличие Infisical CLI-контекста для записи секретов
ansible.builtin.assert:
that:
- lookup('env', 'INFISICAL_TOKEN') | length > 0
- lookup('env', 'INFISICAL_DOMAIN') | length > 0
- lookup('env', 'INFISICAL_PROJECT_ID') | length > 0
fail_msg: "Для роли remnawave нужны INFISICAL_TOKEN / INFISICAL_DOMAIN / INFISICAL_PROJECT_ID (деплой через deploy-machine.sh)."
- name: Проверить имя администратора панели
ansible.builtin.assert:
that:
- remnawave_admin_username | length > 0
fail_msg: "Нужен REMNAWAVE_ADMIN_USER или ADMIN_USER."
# Remnawave v3: /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{24,}$/
- name: Запомнить, какие секреты панели нужно сгенерировать
ansible.builtin.set_fact:
remnawave_need_admin_password: "{{ (remnawave_admin_password | length < 24) or (remnawave_admin_password is not match('^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{24,}$')) }}"
remnawave_need_app_secret: "{{ remnawave_app_secret | length == 0 }}"
remnawave_need_postgres_password: "{{ remnawave_postgres_password | length == 0 }}"
remnawave_need_metrics_pass: "{{ remnawave_metrics_pass | length == 0 }}"
remnawave_need_webhook_secret: "{{ remnawave_webhook_secret | length == 0 }}"
remnawave_need_node_secret: "{{ lookup('env', 'REMNANODE_SECRET_KEY', default='') | length == 0 }}"
- name: Сгенерировать отсутствующие секреты панели
ansible.builtin.set_fact:
remnawave_admin_password: "{{ remnawave_admin_password if not remnawave_need_admin_password else ('Rw9' ~ lookup('password', '/dev/null length=29 chars=ascii_letters,digits')) }}"
remnawave_app_secret: "{{ remnawave_app_secret if not remnawave_need_app_secret else lookup('password', '/dev/null length=64 chars=hexdigits') }}"
remnawave_postgres_password: "{{ remnawave_postgres_password if not remnawave_need_postgres_password else lookup('password', '/dev/null length=48 chars=hexdigits') }}"
remnawave_metrics_pass: "{{ remnawave_metrics_pass if not remnawave_need_metrics_pass else lookup('password', '/dev/null length=64 chars=hexdigits') }}"
remnawave_webhook_secret: "{{ remnawave_webhook_secret if not remnawave_need_webhook_secret else lookup('password', '/dev/null length=64 chars=ascii_letters,digits') }}"
remnawave_secrets_generated: >-
{{
remnawave_need_admin_password or
remnawave_need_app_secret or
remnawave_need_postgres_password or
remnawave_need_metrics_pass or
remnawave_need_webhook_secret
}}
no_log: true
- name: Создать каталоги Remnawave
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: root
group: root
mode: "0755"
loop:
- "{{ remnawave_dir }}"
- "{{ remnawave_subscription_dir }}"
- name: Поставить curl, jq, openssl и python3
ansible.builtin.apt:
name:
- curl
- jq
- openssl
- python3
state: present
- name: Записать .env панели
ansible.builtin.template:
src: env.j2
dest: "{{ remnawave_dir }}/.env"
owner: root
group: root
mode: "0600"
no_log: true
register: remnawave_env_file
- name: Создать папку /services/remnawave в Infisical при необходимости
ansible.builtin.shell: |
set -euo pipefail
infisical secrets folders create \
--domain="${INFISICAL_DOMAIN}" \
--token="${INFISICAL_TOKEN}" \
--env=prod \
--projectId="${INFISICAL_PROJECT_ID}" \
--path="/services" \
--name="remnawave" \
--silent 2>/dev/null || true
args:
executable: /bin/bash
delegate_to: localhost
become: false
environment:
INFISICAL_DOMAIN: "{{ lookup('env', 'INFISICAL_DOMAIN') }}"
INFISICAL_TOKEN: "{{ lookup('env', 'INFISICAL_TOKEN') }}"
INFISICAL_PROJECT_ID: "{{ lookup('env', 'INFISICAL_PROJECT_ID') }}"
when: remnawave_secrets_generated | bool
changed_when: false
- name: Сохранить сгенерированные секреты панели в Infisical
ansible.builtin.shell: |
set -euo pipefail
out=$(infisical secrets set \
--domain="${INFISICAL_DOMAIN}" \
--token="${INFISICAL_TOKEN}" \
--env=prod \
--projectId="${INFISICAL_PROJECT_ID}" \
--path="/services/remnawave" \
"REMNAWAVE_ADMIN_USER=${RW_ADMIN_USER}" \
"REMNAWAVE_ADMIN_PASSWORD=${RW_ADMIN_PASS}" \
"REMNAWAVE_APP_SECRET=${RW_APP_SECRET}" \
"REMNAWAVE_POSTGRES_PASSWORD=${RW_PG_PASS}" \
"REMNAWAVE_METRICS_PASS=${RW_METRICS_PASS}" \
"REMNAWAVE_WEBHOOK_SECRET_HEADER=${RW_WEBHOOK}" \
--silent 2>&1) || {
echo "infisical secrets set failed: ${out}" >&2
exit 1
}
args:
executable: /bin/bash
delegate_to: localhost
become: false
environment:
INFISICAL_DOMAIN: "{{ lookup('env', 'INFISICAL_DOMAIN') }}"
INFISICAL_TOKEN: "{{ lookup('env', 'INFISICAL_TOKEN') }}"
INFISICAL_PROJECT_ID: "{{ lookup('env', 'INFISICAL_PROJECT_ID') }}"
RW_ADMIN_USER: "{{ remnawave_admin_username }}"
RW_ADMIN_PASS: "{{ remnawave_admin_password }}"
RW_APP_SECRET: "{{ remnawave_app_secret }}"
RW_PG_PASS: "{{ remnawave_postgres_password }}"
RW_METRICS_PASS: "{{ remnawave_metrics_pass }}"
RW_WEBHOOK: "{{ remnawave_webhook_secret }}"
when: remnawave_secrets_generated | bool
changed_when: true
no_log: true
- name: Записать compose панели
ansible.builtin.template:
src: compose.yaml.j2
dest: "{{ remnawave_dir }}/compose.yaml"
owner: root
group: root
mode: "0644"
- name: Стянуть образы панели Remnawave
ansible.builtin.command: docker compose -f {{ remnawave_dir }}/compose.yaml pull
register: remnawave_compose_pull
changed_when: "'Pulled' in remnawave_compose_pull.stderr or 'Downloaded' in remnawave_compose_pull.stderr"
retries: 3
delay: 10
until: remnawave_compose_pull.rc == 0
- name: Запустить панель Remnawave
ansible.builtin.command: docker compose -f {{ remnawave_dir }}/compose.yaml up -d --remove-orphans
register: remnawave_compose_up
changed_when: >-
'Started' in remnawave_compose_up.stderr or
'Created' in remnawave_compose_up.stderr or
'Recreated' in remnawave_compose_up.stderr or
'Pulled' in remnawave_compose_up.stderr
- name: Дождаться health панели
ansible.builtin.uri:
url: "http://127.0.0.1:{{ remnawave_metrics_port }}/health"
status_code: 200
register: remnawave_health
retries: 40
delay: 3
until: remnawave_health.status == 200
- name: Дождаться HTTPS панели через Traefik
ansible.builtin.command: >
curl -fsSk --resolve {{ remnawave_panel_domain }}:443:127.0.0.1
https://{{ remnawave_panel_domain }}/api/auth/status
register: remnawave_auth_status
changed_when: false
retries: 30
delay: 5
until: remnawave_auth_status.rc == 0
- name: Инициализировать админа, API-токен (если невалиден) и SECRET_KEY ноды
ansible.builtin.shell: |
set -euo pipefail
API_BASE="https://${RW_PANEL_DOMAIN}/api"
CURL=(curl -sSk --resolve "${RW_PANEL_DOMAIN}:443:127.0.0.1" -H "X-Remnawave-Client-Type: browser")
AUTH_HDR=()
admin_created=0
token_updated=0
node_secret_created=0
active_token="${RW_API_TOKEN:-}"
node_secret="${RW_NODE_SECRET:-}"
redact_json() {
jq 'walk(
if type == "object" then
with_entries(
if (.key | test("(?i)privateKey|privKey|secretKey|SECRET_KEY|accessToken|apiToken|password|^token$"))
then .value = "[REDACTED]"
else . end
)
else . end
)' 2>/dev/null || echo '[body redacted]'
}
api() {
local method="$1"; shift
local path="$1"; shift
local tmp code
tmp=$(mktemp)
if [ -n "${AUTH_HDR[*]:-}" ]; then
code=$("${CURL[@]}" -o "$tmp" -w '%{http_code}' -X "$method" "${AUTH_HDR[@]}" \
-H "Content-Type: application/json" "${API_BASE}${path}" "$@") || true
else
code=$("${CURL[@]}" -o "$tmp" -w '%{http_code}' -X "$method" \
-H "Content-Type: application/json" "${API_BASE}${path}" "$@") || true
fi
if [[ ! "${code}" =~ ^2 ]]; then
echo "API ${method} ${path} -> HTTP ${code}" >&2
redact_json < "$tmp" >&2 || true
rm -f "$tmp"
return 1
fi
cat "$tmp"
rm -f "$tmp"
}
status_json=$("${CURL[@]}" "${API_BASE}/auth/status")
is_register=$(printf '%s' "${status_json}" | jq -r '.response.isRegisterAllowed // .isRegisterAllowed // false')
token_valid=0
if [ "${is_register}" != "true" ] && [ -n "${active_token}" ]; then
tcode=$("${CURL[@]}" -o /dev/null -w '%{http_code}' \
-H "Authorization: Bearer ${active_token}" "${API_BASE}/nodes/" || true)
if [ "${tcode}" = "200" ]; then
token_valid=1
fi
fi
if [ "${is_register}" = "true" ]; then
reg_payload=$(jq -n --arg u "$RW_ADMIN_USER" --arg p "$RW_ADMIN_PASS" '{username: $u, password: $p}')
reg_resp=$(api POST /auth/register -d "${reg_payload}")
access=$(printf '%s' "${reg_resp}" | jq -r '.response.accessToken // .accessToken // empty')
if [ -z "${access}" ]; then
echo "Не удалось зарегистрировать админа Remnawave" >&2
exit 1
fi
AUTH_HDR=(-H "Authorization: Bearer ${access}")
admin_created=1
elif [ "${token_valid}" -eq 0 ] || [ -z "${node_secret}" ]; then
login_payload=$(jq -n --arg u "$RW_ADMIN_USER" --arg p "$RW_ADMIN_PASS" '{username: $u, password: $p}')
login_resp=$(api POST /auth/login -d "${login_payload}")
access=$(printf '%s' "${login_resp}" | jq -r '.response.accessToken // .accessToken // empty')
if [ -z "${access}" ]; then
echo "Не удалось войти в панель Remnawave" >&2
exit 1
fi
AUTH_HDR=(-H "Authorization: Bearer ${access}")
fi
if [ "${token_valid}" -eq 0 ]; then
tokens_json=$(api GET /tokens/ || echo '{"response":[]}')
old_uuids=$(printf '%s' "${tokens_json}" | jq -r --arg n "$RW_TOKEN_NAME" '
(.response // .)
| if type=="array" then . elif .tokens then .tokens else [] end
| map(select(.name == $n or .tokenName == $n) | .uuid)
| .[]')
for old_uuid in ${old_uuids}; do
[ -n "${old_uuid}" ] || continue
api DELETE "/tokens/${old_uuid}" >/dev/null || true
done
scopes_json=$(api GET /tokens/scopes || echo '{"response":{"wildcard":"*"}}')
wildcard=$(printf '%s' "${scopes_json}" | jq -r '.response.wildcard // "*"')
token_payload=$(jq -n --arg n "$RW_TOKEN_NAME" --arg s "${wildcard:-*}" \
'{name: $n, expiresInDays: 3650, scopes: [$s]}')
token_resp=$(api POST /tokens/ -d "${token_payload}")
created=$(printf '%s' "${token_resp}" | jq -r '
.response.token // .response.apiToken // .token // .apiToken // empty')
if [ -z "${created}" ]; then
echo "Не удалось создать API-токен Remnawave" >&2
exit 1
fi
active_token="${created}"
token_updated=1
fi
if [ -z "${node_secret}" ]; then
keygen_resp=$(api GET /keygen/)
node_secret=$(printf '%s' "${keygen_resp}" | jq -r '.response.secretKey // .secretKey // empty')
if [ -z "${node_secret}" ]; then
echo "Не удалось получить SECRET_KEY ноды из /api/keygen/" >&2
exit 1
fi
node_secret_created=1
fi
umask 077
jq -n --arg api_token "${active_token}" --arg node_secret "${node_secret}" \
'{api_token: $api_token, node_secret: $node_secret}' > "${RW_SECRETS_FILE}"
chmod 600 "${RW_SECRETS_FILE}"
jq -n \
--argjson admin_created "${admin_created}" \
--argjson token_updated "${token_updated}" \
--argjson node_secret_created "${node_secret_created}" \
'{
admin_created: ($admin_created == 1),
token_updated: ($token_updated == 1),
node_secret_created: ($node_secret_created == 1),
changed: (($admin_created + $token_updated + $node_secret_created) > 0)
}'
args:
executable: /bin/bash
environment:
RW_PANEL_DOMAIN: "{{ remnawave_panel_domain }}"
RW_ADMIN_USER: "{{ remnawave_admin_username }}"
RW_ADMIN_PASS: "{{ remnawave_admin_password }}"
RW_API_TOKEN: "{{ remnawave_api_token }}"
RW_NODE_SECRET: "{{ lookup('env', 'REMNANODE_SECRET_KEY', default='') }}"
RW_TOKEN_NAME: "{{ remnawave_api_token_name }}"
RW_SECRETS_FILE: "{{ remnawave_dir }}/.bootstrap-secrets.json"
register: remnawave_bootstrap_raw
changed_when: (remnawave_bootstrap_raw.stdout | from_json).changed
no_log: true
- name: Разобрать статус bootstrap
ansible.builtin.set_fact:
remnawave_bootstrap: "{{ remnawave_bootstrap_raw.stdout | from_json }}"
- name: Прочитать API-токен и SECRET_KEY
ansible.builtin.slurp:
src: "{{ remnawave_dir }}/.bootstrap-secrets.json"
register: remnawave_bootstrap_secrets
no_log: true
- name: Подставить секреты bootstrap в факты
ansible.builtin.set_fact:
remnawave_api_token: "{{ (remnawave_bootstrap_secrets.content | b64decode | from_json).api_token }}"
remnawave_node_secret: "{{ (remnawave_bootstrap_secrets.content | b64decode | from_json).node_secret }}"
no_log: true
- name: Записать .env subscription-page
ansible.builtin.template:
src: subscription.env.j2
dest: "{{ remnawave_subscription_dir }}/.env"
owner: root
group: root
mode: "0600"
no_log: true
register: remnawave_sub_env
- name: Записать compose subscription-page
ansible.builtin.template:
src: subscription-compose.yaml.j2
dest: "{{ remnawave_subscription_dir }}/compose.yaml"
owner: root
group: root
mode: "0644"
register: remnawave_sub_compose
- name: Запустить subscription-page
ansible.builtin.command: docker compose -f {{ remnawave_subscription_dir }}/compose.yaml up -d --remove-orphans
register: remnawave_sub_up
changed_when: >-
'Started' in remnawave_sub_up.stderr or
'Created' in remnawave_sub_up.stderr or
'Recreated' in remnawave_sub_up.stderr or
'Pulled' in remnawave_sub_up.stderr
- name: Дождаться subscription-page (docker health)
ansible.builtin.shell: |
docker inspect remnawave-subscription-page --format '{% raw %}{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}{% endraw %}'
register: remnawave_sub_health
changed_when: false
retries: 30
delay: 2
until: (remnawave_sub_health.stdout | trim) == 'healthy'
@@ -0,0 +1,78 @@
---
- name: Развернуть и инициализировать панель Remnawave
ansible.builtin.include_tasks: bootstrap.yml
- name: Синхронизировать ноды, профили, шаблоны и пользователей Remnawave
ansible.builtin.include_tasks: sync.yml
- name: Определить изменившиеся секреты для Infisical
ansible.builtin.set_fact:
remnawave_current_xray_url: "{{ lookup('env', 'XRAY_CHECKER_SUBSCRIPTION_URL', default='') }}"
remnawave_need_infisical_sync: >-
{{
(remnawave_bootstrap.token_updated | default(false)) or
(remnawave_bootstrap.node_secret_created | default(false)) or
((remnawave_xray_checker_url | default('') | length > 0) and (remnawave_xray_checker_url != lookup('env', 'XRAY_CHECKER_SUBSCRIPTION_URL', default='')))
}}
no_log: true
- name: Сохранить API-токен, SECRET_KEY ноды и ссылку Xray Checker в Infisical при изменении
ansible.builtin.shell: |
set -euo pipefail
args=(
"REMNAWAVE_API_TOKEN=${RW_API_TOKEN}"
"REMNANODE_SECRET_KEY=${RW_NODE_SECRET}"
)
if [ -n "${RW_XRAY_URL:-}" ]; then
args+=("XRAY_CHECKER_SUBSCRIPTION_URL=${RW_XRAY_URL}")
fi
infisical secrets set \
--domain="${INFISICAL_DOMAIN}" \
--token="${INFISICAL_TOKEN}" \
--env=prod \
--projectId="${INFISICAL_PROJECT_ID}" \
--path="/services/remnawave" \
"${args[@]}" \
--silent >/dev/null
args:
executable: /bin/bash
delegate_to: localhost
become: false
environment:
INFISICAL_DOMAIN: "{{ lookup('env', 'INFISICAL_DOMAIN') }}"
INFISICAL_TOKEN: "{{ lookup('env', 'INFISICAL_TOKEN') }}"
INFISICAL_PROJECT_ID: "{{ lookup('env', 'INFISICAL_PROJECT_ID') }}"
RW_API_TOKEN: "{{ remnawave_api_token }}"
RW_NODE_SECRET: "{{ remnawave_node_secret | default(lookup('env', 'REMNANODE_SECRET_KEY', default='')) }}"
RW_XRAY_URL: "{{ remnawave_xray_checker_url | default('') }}"
when:
- remnawave_api_token | default('') | length > 0
- remnawave_need_infisical_sync | bool
changed_when: true
no_log: true
- name: Зарегистрировать панель Remnawave в Agent Vault
ansible.builtin.include_role:
name: agent_vault_service
vars:
agent_vault_service_name: remnawave-panel
agent_vault_service_description: >-
Панель Remnawave (rw.gunihome.ru): ноды, пользователи и подписки VPN.
Креденшл — сервисный API-токен панели.
agent_vault_service_host: "{{ remnawave_panel_domain }}:443"
agent_vault_service_paths: ["/api"]
agent_vault_service_methods: [GET, POST]
agent_vault_secret_path: /services/remnawave
agent_vault_secret_key: REMNAWAVE_API_TOKEN
when: remnawave_api_token | default('') | length > 0
- name: Итог Remnawave panel
ansible.builtin.debug:
msg:
- "Панель: https://{{ remnawave_panel_domain }}"
- "Подписка: https://{{ remnawave_sub_domain }}"
- "Админ создан в этом прогоне: {{ remnawave_bootstrap.admin_created | default(false) }}"
- "API-токен обновлён в Infisical: {{ remnawave_bootstrap.token_updated | default(false) }}"
- "SECRET_KEY ноды получен в этом прогоне: {{ remnawave_bootstrap.node_secret_created | default(false) }}"
- "Изменения sync (nodes.yml / users.yml): {{ remnawave_sync.changes | default([]) }}"
- "Предупреждения sync: {{ remnawave_sync.warnings | default([]) }}"
@@ -0,0 +1,61 @@
---
- name: Загрузить декларативную конфигурацию нод и пользователей Remnawave
ansible.builtin.set_fact:
remnawave_nodes_cfg: "{{ lookup('file', role_path ~ '/files/nodes.yml') | from_yaml }}"
remnawave_users_cfg: "{{ lookup('file', role_path ~ '/files/users.yml') | from_yaml }}"
- name: Проверить, что панель сама в NetBird
ansible.builtin.command: netbird status
register: remnawave_local_netbird
changed_when: false
failed_when: false
- name: Собрать конфигурацию синхронизации Remnawave
ansible.builtin.set_fact:
remnawave_sync_payload:
panel_domain: "{{ remnawave_panel_domain }}"
sub_domain: "{{ remnawave_sub_domain }}"
netbird_peers_url: "{{ remnawave_netbird_peers_url }}"
netbird_connected: "{{ 'Management: Connected' in (remnawave_local_netbird.stdout | default('')) }}"
xray_checker_user: "{{ remnawave_xray_checker_user }}"
xray_template: "{{ remnawave_nodes_cfg.xray_template }}"
xray_template_json: "{{ lookup('file', role_path ~ '/files/' ~ remnawave_nodes_cfg.xray_template.file) | from_json }}"
squad_name: "{{ remnawave_nodes_cfg.squad_name | default('Default-Squad') }}"
subscription_page_config: "{{ remnawave_nodes_cfg.subscription_page_config | default('Homelab') }}"
nodes: "{{ remnawave_nodes_cfg.nodes | default([]) }}"
managed_tag: "{{ remnawave_users_cfg.managed_tag | default('IAC') }}"
users: "{{ remnawave_users_cfg.users | default([]) }}"
profile_templates:
profile-selfsteal-xhttp.json: "{{ lookup('file', role_path ~ '/files/profile-selfsteal-xhttp.json') }}"
- name: Положить скрипт синхронизации Remnawave
ansible.builtin.copy:
src: sync_remnawave.py
dest: "{{ remnawave_dir }}/sync_remnawave.py"
owner: root
group: root
mode: "0700"
- name: Записать конфигурацию синхронизации Remnawave
ansible.builtin.copy:
dest: "{{ remnawave_dir }}/sync_config.json"
content: "{{ remnawave_sync_payload | to_json }}"
owner: root
group: root
mode: "0600"
- name: Синхронизировать шаблоны, профили, ноды, хосты и пользователей Remnawave
ansible.builtin.command: "python3 {{ remnawave_dir }}/sync_remnawave.py {{ remnawave_dir }}/sync_config.json"
environment:
RW_API_TOKEN: "{{ remnawave_api_token }}"
NB_API_TOKEN: "{{ lookup('env', 'NETBIRD_API_TOKEN', default='') }}"
register: remnawave_sync_raw
changed_when: (remnawave_sync_raw.stdout | from_json).changed
no_log: true
- name: Разобрать результат синхронизации Remnawave
ansible.builtin.set_fact:
remnawave_sync: "{{ remnawave_sync_raw.stdout | from_json }}"
remnawave_xray_checker_url: "{{ (remnawave_sync_raw.stdout | from_json).xray_checker_subscription_url | default('') }}"
no_log: true
@@ -0,0 +1,101 @@
# Без ulimits nofile: на unprivileged LXC (core-net) rlimit 1048576 даёт
# "error setting rlimit type 7: operation not permitted".
x-logging: &logging
logging:
driver: json-file
options:
max-size: 100m
max-file: 5
services:
remnawave:
image: {{ remnawave_backend_image }}
container_name: remnawave
hostname: remnawave
restart: always
env_file: .env
<<: *logging
networks:
- remnawave-network
volumes:
- valkey-socket:/var/run/valkey
ports:
- "127.0.0.1:{{ remnawave_app_port }}:{{ remnawave_app_port }}"
- "127.0.0.1:{{ remnawave_metrics_port }}:{{ remnawave_metrics_port }}"
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:{{ remnawave_metrics_port }}/health"]
interval: 30s
timeout: 5s
retries: 3
start_period: 30s
depends_on:
remnawave-db:
condition: service_healthy
remnawave-redis:
condition: service_healthy
remnawave-db:
image: {{ remnawave_postgres_image }}
container_name: remnawave-db
hostname: remnawave-db
shm_size: 512mb
restart: always
env_file: .env
<<: *logging
networks:
- remnawave-network
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
- TZ=UTC
ports:
- "127.0.0.1:6767:5432"
volumes:
- remnawave-db-data:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 3s
timeout: 10s
retries: 3
remnawave-redis:
image: {{ remnawave_redis_image }}
container_name: remnawave-redis
hostname: remnawave-redis
restart: always
<<: *logging
networks:
- remnawave-network
volumes:
- valkey-socket:/var/run/valkey
command: >
valkey-server
--save ""
--appendonly no
--maxmemory-policy noeviction
--loglevel warning
--unixsocket /var/run/valkey/valkey.sock
--unixsocketperm 777
--port 0
healthcheck:
test: ["CMD", "valkey-cli", "-s", "/var/run/valkey/valkey.sock", "ping"]
interval: 3s
timeout: 3s
retries: 3
networks:
remnawave-network:
name: remnawave-network
driver: bridge
external: false
volumes:
remnawave-db-data:
name: remnawave-db-data
driver: local
external: false
valkey-socket:
name: valkey-socket
driver: local
external: false
@@ -0,0 +1,59 @@
### APP ###
APP_PORT={{ remnawave_app_port }}
METRICS_PORT={{ remnawave_metrics_port }}
### API ###
API_INSTANCES=1
### DATABASE ###
DATABASE_URL="postgresql://postgres:{{ remnawave_postgres_password }}@remnawave-db:5432/postgres"
### REDIS ###
REDIS_SOCKET=/var/run/valkey/valkey.sock
### Secrets ###
APP_SECRET={{ remnawave_app_secret }}
### TELEGRAM NOTIFICATIONS ###
IS_TELEGRAM_NOTIFICATIONS_ENABLED=false
TELEGRAM_BOT_TOKEN=change_me
TELEGRAM_NOTIFY_USERS=change_me
TELEGRAM_NOTIFY_NODES=change_me
TELEGRAM_NOTIFY_CRM=change_me
TELEGRAM_NOTIFY_SERVICE=change_me
TELEGRAM_NOTIFY_TBLOCKER=change_me
### PANEL DOMAIN ###
PANEL_DOMAIN={{ remnawave_panel_domain }}
### FRONT_END ###
FRONT_END_DOMAIN={{ remnawave_panel_domain }}
### SUBSCRIPTION PUBLIC DOMAIN ###
SUB_PUBLIC_DOMAIN={{ remnawave_sub_domain }}
### PROMETHEUS ###
METRICS_USER=admin
METRICS_PASS={{ remnawave_metrics_pass }}
### Webhook ###
WEBHOOK_ENABLED=false
WEBHOOK_URL=https://your-webhook-url.com/endpoint
WEBHOOK_SECRET_HEADER={{ remnawave_webhook_secret }}
BANDWIDTH_USAGE_NOTIFICATIONS_ENABLED=false
BANDWIDTH_USAGE_NOTIFICATIONS_THRESHOLD=[60, 80]
NOT_CONNECTED_USERS_NOTIFICATIONS_ENABLED=false
NOT_CONNECTED_USERS_NOTIFICATIONS_AFTER_HOURS=[6, 24, 48]
EXPIRATION_NOTIFICATIONS_ENABLED=false
EXPIRATION_NOTIFICATIONS=[-72, -48, -24, 24]
EXPORT_TO_STREAM_ENABLED=false
EXPORT_TO_STREAM_MAXLEN=3000
SHORT_UUID_METHOD=nanoid
SHORT_UUID_LENGTH=16
SERVICE_SNI_VERIFICATION=true
### Database container ###
POSTGRES_USER=postgres
POSTGRES_PASSWORD={{ remnawave_postgres_password }}
POSTGRES_DB=postgres
@@ -0,0 +1,23 @@
services:
remnawave-subscription-page:
image: {{ remnawave_subscription_image }}
container_name: remnawave-subscription-page
hostname: remnawave-subscription-page
restart: always
env_file:
- .env
ports:
- "127.0.0.1:{{ remnawave_subscription_port }}:{{ remnawave_subscription_port }}"
networks:
- remnawave-network
logging:
driver: json-file
options:
max-size: 30m
max-file: 5
networks:
remnawave-network:
name: remnawave-network
driver: bridge
external: true
@@ -0,0 +1,5 @@
APP_PORT={{ remnawave_subscription_port }}
REMNAWAVE_PANEL_URL=http://remnawave:{{ remnawave_app_port }}
REMNAWAVE_API_TOKEN={{ remnawave_api_token }}
CUSTOM_SUB_PREFIX=
TRUST_PROXY=1
@@ -0,0 +1,7 @@
---
traefik_version: "v3.3.7"
traefik_dir: "/opt/traefik"
traefik_dynamic_dir: "/opt/traefik/dynamic"
traefik_log_dir: "/var/log/traefik"
traefik_acme_email: "{{ letsencrypt_email }}"
traefik_dashboard_auth: "{{ lookup('ansible.builtin.env', 'TRAEFIK_DASHBOARD_AUTH', default='') }}"
@@ -0,0 +1,13 @@
# Известный бардак
Этот каталог специально оставлен плоским, пока старая инфраструктура не переедет на схему «машина → продукт» (`ansible/roles/<машина>/<продукт>/`).
Здесь вперемешку лежат три разных вещи:
- маршруты сервисов, которые этот репозиторий сам ставит (`remnawave.yml`, `grafana.yml`, `infisical.yml`);
- маршруты сервисов на других машинах;
- старые приложения, которые репозиторий только проксирует. Имя файла часто равно поддомену (`tv.yml`, `spot.yml`, `pass.yml`), а не программе. Compose этих приложений здесь нет.
Разбор будет после перевода всей старой инфры на эти рельсы. До тех пор файлы не переименовывать и не раскладывать по подкаталогам: роль копирует каталог на `core-net` целиком и удаляет с сервера YAML, которых больше нет в Git.
Traefik этот файл не читает: в провайдер попадают только `*.yml` и `*.yaml`.
@@ -0,0 +1,35 @@
# Известный бардак старых маршрутов. Разбор после перевода старой инфры на роли машин. См. README.md в этом каталоге.
http:
routers:
authentik:
rule: "Host(`auth.gunihome.ru`)"
entryPoints:
- websecure
service: authentik
tls:
certResolver: letsencrypt
services:
authentik:
loadBalancer:
servers:
- url: "http://127.0.0.1:9000"
middlewares:
authentik:
forwardAuth:
address: "http://127.0.0.1:9000/outpost.goauthentik.io/auth/traefik"
trustForwardHeader: true
authResponseHeaders:
- "X-authentik-username"
- "X-authentik-groups"
- "X-authentik-email"
- "X-authentik-name"
- "X-authentik-uid"
- "X-authentik-jwt"
- "X-authentik-meta-jwks"
- "X-authentik-meta-outpost"
- "X-authentik-meta-provider"
- "X-authentik-meta-app"
- "X-authentik-meta-version"
@@ -0,0 +1,16 @@
# Известный бардак старых маршрутов. Разбор после перевода старой инфры на роли машин. См. README.md в этом каталоге.
http:
routers:
books:
rule: "Host(`books.gunihome.ru`)"
entryPoints:
- websecure
service: books
tls:
certResolver: letsencrypt
services:
books:
loadBalancer:
servers:
- url: "http://192.168.1.210:13378"
@@ -0,0 +1,28 @@
# Известный бардак старых маршрутов. Разбор после перевода старой инфры на роли машин. См. README.md в этом каталоге.
http:
routers:
nextcloud:
entryPoints:
- "websecure"
rule: "Host(`cloud.gunihome.ru`)"
middlewares:
- nextcloud-secure-headers
service: nextcloud
tls:
certResolver: "letsencrypt"
services:
nextcloud:
loadBalancer:
servers:
- url: "http://192.168.1.209:11000"
passHostHeader: true
middlewares:
nextcloud-secure-headers:
headers:
hostsProxyHeaders:
- "X-Forwarded-Host"
referrerPolicy: "same-origin"
customResponseHeaders:
X-Robots-Tag: "noindex, nofollow"
@@ -0,0 +1,19 @@
# Известный бардак старых маршрутов. Разбор после перевода старой инфры на роли машин. См. README.md в этом каталоге.
http:
routers:
erpnext:
rule: "Host(`erpnext.gunihome.ru`)"
entryPoints:
- websecure
service: erpnext
tls:
certResolver: letsencrypt
services:
erpnext:
loadBalancer:
servers:
- url: "http://192.168.1.120:80"
@@ -0,0 +1,16 @@
# Известный бардак старых маршрутов. Разбор после перевода старой инфры на роли машин. См. README.md в этом каталоге.
http:
routers:
gitea:
rule: "Host(`gitea.gunihome.ru`)"
entryPoints:
- websecure
service: gitea
tls:
certResolver: letsencrypt
services:
gitea:
loadBalancer:
servers:
- url: "http://192.168.1.105:3000"
@@ -0,0 +1,16 @@
# Известный бардак старых маршрутов. Разбор после перевода старой инфры на роли машин. См. README.md в этом каталоге.
http:
routers:
grafana:
rule: "Host(`graf.gunihome.ru`)"
entryPoints:
- websecure
service: grafana
tls:
certResolver: letsencrypt
services:
grafana:
loadBalancer:
servers:
- url: "http://192.168.1.108:3000"
@@ -0,0 +1,20 @@
# Известный бардак старых маршрутов. Разбор после перевода старой инфры на роли машин. См. README.md в этом каталоге.
# Динамическая конфигурация Traefik для Infisical
# infisical.gunihome.ru -> 192.168.1.102:8080
http:
routers:
infisical:
rule: "Host(`infisical.gunihome.ru`)"
entryPoints:
- websecure
service: infisical
tls:
certResolver: letsencrypt
services:
infisical:
loadBalancer:
servers:
- url: "http://192.168.1.102:8080"
Loaded 100 of 197 files, more files were not shown because too many files have changed in this diff. Show more