Files
ansible-config/roles/grafana/tasks/wait_and_verify.yml

111 lines
3.7 KiB
YAML

---
- name: Phase 1: Initial wait for Grafana to start
pause:
seconds: 60
prompt: "Phase 1/5: Initial wait for Grafana startup (60 seconds)..."
tags: grafana
- name: Check if Grafana service is active (with retries)
shell: |
systemctl is-active grafana
register: grafana_active
until: grafana_active.stdout == "active"
retries: 60 # 60 * 5 = 300 секунд (5 минут)
delay: 5
tags: grafana
- name: Phase 2: Wait for database migrations (wave 1)
pause:
seconds: 180
prompt: "Phase 2/5: Waiting for database migrations (180 seconds)..."
tags: grafana
- name: Phase 3: Wait for plugins installation (wave 2)
pause:
seconds: 180
prompt: "Phase 3/5: Waiting for plugins installation (180 seconds)..."
tags: grafana
- name: Phase 4: Wait for HTTP server startup (wave 3)
pause:
seconds: 180
prompt: "Phase 4/5: Waiting for HTTP server startup (180 seconds)..."
tags: grafana
- name: Check if port 3000 is listening (with very long timeout)
wait_for:
port: 3000
host: 127.0.0.1
timeout: 600 # 10 минут
state: started
register: port_check
tags: grafana
- name: Phase 5: Final verification (wave 4)
pause:
seconds: 120
prompt: "Phase 5/5: Final verification (120 seconds)..."
tags: grafana
- name: Check Grafana API health (with many retries)
uri:
url: "http://localhost:3000/api/health"
method: GET
status_code: 200
timeout: 10
register: api_check
until: api_check.status == 200
retries: 60 # 60 * 5 = 300 секунд (5 минут)
delay: 5
tags: grafana
- name: Calculate total wait time
set_fact:
total_wait_time: "{{ 60 + 180 + 180 + 180 + 120 }}"
tags: grafana
- name: Show installation success with detailed info
debug:
msg: |
🎉 Grafana успешно установлена и готова к работе!
⏱️ Общее время установки: {{ total_wait_time }} секунд
📊 Статус компонентов:
• Служба: ✅ {{ grafana_active.stdout }}
• Порт 3000: {{ '✅ открыт' if port_check is defined and port_check.state == 'started' else '❌ закрыт' }}
• API: {{ '✅ доступен (HTTP ' ~ api_check.status ~ ')' if api_check is defined and api_check.status == 200 else '❌ недоступен' }}
🔗 Доступ:
• URL: http://{{ inventory_hostname }}:3000
• Логин: admin
• Пароль: {{ grafana_admin_password | default('admin') }}
📋 Для проверки выполните:
curl http://{{ inventory_hostname }}:3000/api/health
💡 Примечание: Первый запуск Grafana занимает время из-за:
1. Миграций базы данных
2. Установки плагинов по умолчанию
3. Инициализации сервиса
Последующие запуски будут значительно быстрее.
tags: grafana
- name: Final check from control node (optional)
delegate_to: localhost
run_once: yes
when: false # Отключено по умолчанию, можно включить
tags: grafana
block:
- name: Test external access
uri:
url: "http://{{ hostvars[groups['grafana'][0]]['ansible_default_ipv4']['address'] | default(groups['grafana'][0]) }}:3000/api/health"
method: GET
status_code: 200
timeout: 30
register: external_check
- name: Show external access result
debug:
msg: "External access: {{ '✅ успешно' if external_check.status == 200 else '❌ недоступно' }}"