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

This commit is contained in:
karpenok committed 2026-11-11 17:45:21 +07:00
1 parent 94a143623b
commit c0a9d7f0c8
16 files changed
+15726 -263

No files matched your search

@@ -2,11 +2,12 @@
monitoring_dir: /opt/monitoring
prometheus_retention: "30d"
grafana_admin_user: "{{ lookup('ansible.builtin.env', 'GRAFANA_ADMIN_USER', default='admin') }}"
grafana_admin_user: "{{ lookup('ansible.builtin.env', 'GRAFANA_ADMIN_USER', default='karpenok') }}"
grafana_admin_password: "{{ lookup('ansible.builtin.env', 'GRAFANA_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"
grafana_oauth_client_secret: "{{ lookup('ansible.builtin.env', 'GRAFANA_OAUTH_CLIENT_SECRET', default='') }}"
ntfy_base_url: "https://ntfy.gunihome.ru"
ntfy_default_topic: "homelab-alerts"
ntfy_admin_user: "{{ lookup('ansible.builtin.env', 'NTFY_ADMIN_USER', default=grafana_admin_user) }}"
ntfy_admin_password: "{{ lookup('ansible.builtin.env', 'NTFY_ADMIN_PASSWORD', default=grafana_admin_password) }}"
File diff suppressed because it is too large. Load diff
@@ -1,10 +1,4 @@
---
- name: Проверить наличие секрета Grafana OAuth
ansible.builtin.assert:
that:
- grafana_oauth_client_secret is defined and grafana_oauth_client_secret | length > 0
fail_msg: "Секрет GRAFANA_OAUTH_CLIENT_SECRET не передан!"
- name: Создать базовые каталоги мониторинга
ansible.builtin.file:
path: "{{ item.path }}"
@@ -22,6 +16,7 @@
- { 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" }
- name: Установить конфигурацию Prometheus
@@ -56,6 +51,22 @@
group: root
mode: "0644"
- name: Установить провайдер дашбордов Grafana
ansible.builtin.template:
src: grafana-dashboards.yml.j2
dest: "{{ monitoring_dir }}/grafana/provisioning/dashboards/dashboards.yml"
owner: root
group: root
mode: "0644"
- name: Скопировать статические дашборды Grafana
ansible.builtin.copy:
src: dashboards/
dest: "{{ monitoring_dir }}/grafana/provisioning/dashboards/"
owner: root
group: root
mode: "0644"
- name: Установить compose.yaml для стека мониторинга
ansible.builtin.template:
src: compose.yaml.j2
@@ -69,6 +80,32 @@
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: Дождаться готовности 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
- name: Дождаться готовности Grafana
ansible.builtin.uri:
url: "http://127.0.0.1:3000/api/health"
@@ -78,11 +115,16 @@
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 --password-from-stdin
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
@@ -13,4 +13,8 @@ receivers:
webhook_configs:
- url: "http://ntfy:80/{{ ntfy_default_topic }}"
send_resolved: true
http_config:
basic_auth:
username: "{{ ntfy_admin_user }}"
password: "{{ ntfy_admin_password }}"
@@ -41,6 +41,8 @@ services:
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_CACHE_FILE=/var/cache/ntfy/cache.db
- NTFY_ATTACHMENT_CACHE_DIR=/var/cache/ntfy/attachments
volumes:
@@ -57,21 +59,6 @@ services:
- GF_SECURITY_ADMIN_PASSWORD={{ grafana_admin_password }}
- GF_USERS_ALLOW_SIGN_UP=false
- GF_SERVER_ROOT_URL={{ grafana_root_url }}
- GF_AUTH_GENERIC_OAUTH_ENABLED=true
- GF_AUTH_GENERIC_OAUTH_NAME=Authentik
- GF_AUTH_GENERIC_OAUTH_CLIENT_ID=grafana
- GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET={{ grafana_oauth_client_secret }}
- GF_AUTH_GENERIC_OAUTH_SCOPES=openid email profile
- GF_AUTH_GENERIC_OAUTH_AUTH_URL=https://auth.gunihome.ru/application/o/authorize/
- GF_AUTH_GENERIC_OAUTH_TOKEN_URL=https://auth.gunihome.ru/application/o/token/
- GF_AUTH_GENERIC_OAUTH_API_URL=https://auth.gunihome.ru/application/o/userinfo/
- GF_AUTH_GENERIC_OAUTH_ALLOW_SIGN_UP=true
- GF_AUTH_GENERIC_OAUTH_LOGIN_ATTRIBUTE_PATH=preferred_username
- GF_AUTH_GENERIC_OAUTH_NAME_ATTRIBUTE_PATH=name
- GF_AUTH_GENERIC_OAUTH_EMAIL_ATTRIBUTE_PATH=email
- GF_AUTH_GENERIC_OAUTH_USE_PKCE=true
- "GF_AUTH_GENERIC_OAUTH_ROLE_ATTRIBUTE_PATH=contains(groups[*], 'admins') && 'Admin' || 'Viewer'"
- GF_AUTH_GENERIC_OAUTH_ALLOW_ASSIGN_GRAFANA_ADMIN=true
volumes:
- ./grafana_data:/var/lib/grafana
- ./grafana/provisioning:/etc/grafana/provisioning:ro
@@ -0,0 +1,11 @@
apiVersion: 1
providers:
- name: 'default'
orgId: 1
folder: 'Homelab'
type: file
disableDeletion: false
editable: true
options:
path: /etc/grafana/provisioning/dashboards
@@ -2,6 +2,7 @@ apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus
type: prometheus
access: proxy
url: http://prometheus:9090