Добавлена установка Grafana: роли, плейбуки и конфигурация

This commit is contained in:
Freazzzing
2026-02-04 02:28:50 +00:00
parent 0abdb8b0a5
commit 17dd0fddff
17 changed files with 745 additions and 0 deletions

View File

@ -0,0 +1,47 @@
---
- name: Check Grafana installation status
hosts: grafana
become: yes
tasks:
- name: Check Grafana service
systemd:
name: grafana
register: service_status
- name: Check if Grafana is listening on port
wait_for:
port: 3000
host: 127.0.0.1
timeout: 10
state: started
register: port_status
- name: Check Grafana API health
uri:
url: "http://localhost:3000/api/health"
method: GET
status_code: 200
timeout: 10
register: api_status
ignore_errors: yes
- name: Get Grafana version
command: /usr/local/bin/grafana-server --version
register: version_info
changed_when: false
ignore_errors: yes
- name: Display Grafana status report
debug:
msg: |
📊 Статус Grafana на {{ inventory_hostname }}:
Служба: {{ "✅ Запущена" if service_status.status.ActiveState == "active" else "❌ Остановлена" }}
Порт 3000: {{ "✅ Открыт" if port_status.state == "started" else "❌ Закрыт" }}
API: {{ "✅ Доступен (HTTP " ~ api_status.status ~ ")" if api_status.status == 200 else "❌ Недоступен" }}
{% if version_info is succeeded %}
Версия: {{ version_info.stdout_lines[-1] | regex_search('Version ([0-9.]+)') | default('Неизвестна') }}
{% else %}
Версия: Не удалось определить
{% endif %}

View File

@ -0,0 +1,55 @@
---
- name: Clean up Grafana completely
hosts: grafana
become: yes
tasks:
- name: Stop and disable Grafana service
systemd:
name: grafana
state: stopped
enabled: no
daemon_reload: yes
ignore_errors: yes
- name: Remove systemd service file
file:
path: /etc/systemd/system/grafana.service
state: absent
- name: Remove symlinks
file:
path: "{{ item }}"
state: absent
loop:
- /usr/local/bin/grafana-server
- /usr/local/bin/grafana-cli
- name: Remove Grafana directories
file:
path: "{{ item }}"
state: absent
loop:
- /usr/share/grafana
- /usr/share/grafana-*
- /var/lib/grafana
- /var/log/grafana
- /etc/grafana
- name: Remove temporary files
file:
path: /tmp/grafana-*.tar.gz
state: absent
- name: Remove Grafana user and group
user:
name: grafana
state: absent
remove: yes
- name: Reload systemd
systemd:
daemon_reload: yes
- name: Verify cleanup
debug:
msg: "✅ Grafana полностью удалена с хоста {{ inventory_hostname }}"

View File

@ -0,0 +1,9 @@
---
- name: Install and configure Grafana
hosts: grafana
become: yes
vars:
grafana_version: "12.3.2"
grafana_admin_password: "admin"
roles:
- grafana

View File

@ -0,0 +1,47 @@
---
- name: Install and configure Grafana (with health checks)
hosts: grafana
become: yes
vars:
grafana_version: "12.3.2"
grafana_admin_password: "admin"
tasks:
- name: Include Grafana role
include_role:
name: grafana
- name: Final verification from control node
delegate_to: localhost
run_once: yes
block:
- name: Wait for Grafana to be fully ready
pause:
seconds: 30
prompt: "Waiting for Grafana to complete initialization..."
- name: Test Grafana access from control node
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: final_check
until: final_check.status == 200
retries: 12 # 12 попыток * 5 секунд = 60 секунд
delay: 5
- name: Display final success message
debug:
msg: |
🎉 Grafana успешно установлена и готова к работе!
Доступ по адресу: http://{{ hostvars[groups['grafana'][0]]['ansible_default_ipv4']['address'] | default(groups['grafana'][0]) }}:3000
Логин: admin
Пароль: {{ grafana_admin_password }}
Для проверки выполните команду:
curl http://{{ hostvars[groups['grafana'][0]]['ansible_default_ipv4']['address'] | default(groups['grafana'][0]) }}:3000/api/health
Или откройте в браузере:
http://{{ hostvars[groups['grafana'][0]]['ansible_default_ipv4']['address'] | default(groups['grafana'][0]) }}:3000