Update file main.yml

This commit is contained in:
Administrator 2025-11-18 07:06:44 +00:00
parent 1756b1b403
commit 2edd629124

View File

@ -58,7 +58,6 @@
- /opt/pve_exporter/config
become: yes
# Устанавливаем sudo для корректной работы become
- name: Ensure sudo is installed
apt:
name: sudo
@ -101,8 +100,7 @@
mode: '0600'
become: yes
# УДАЛЯЕМ задачу с --test - этот флаг не поддерживается
# Вместо этого проверяем логи при ошибке
# УБИРАЕМ проверку с --test (она не поддерживается)
- name: Create pve_exporter systemd service
copy:
@ -139,45 +137,40 @@
state: started
daemon_reload: yes
become: yes
register: service_start
failed_when: false
- name: Wait for pve_exporter to initialize
wait_for:
host: localhost
port: 9223
timeout: 60
state: started
delay: 5
register: port_check
failed_when: false
- name: Wait for service to initialize
pause:
seconds: 10
become: yes
- name: Show pve_exporter logs if failed
command: journalctl -u pve_exporter -n 100 --no-pager
# Проверяем статус сервиса
- name: Check pve_exporter service status
command: systemctl status pve_exporter
register: service_status
changed_when: false
become: yes
# Если сервис не активен - показываем логи
- name: Show pve_exporter logs
command: journalctl -u pve_exporter --since "5 minutes ago" --no-pager
register: service_logs
changed_when: false
when: port_check.failed
when: "'Active: failed' in service_status.stdout or 'Active: inactive' in service_status.stdout"
become: yes
failed_when: false
# Проверяем открытые порты
- name: Check listening ports
command: ss -tlnp | grep ':9223'
register: port_status
changed_when: false
become: yes
# Финальная проверка
- name: Verify exporter is responding
uri:
url: http://localhost:9223/metrics
status_code: 200
timeout: 10
register: metrics_check
when: not port_check.failed
failed_when: metrics_check.status != 200
become: yes
- name: Fail with detailed error if pve_exporter not started
fail:
msg: |
pve_exporter failed to start. Common causes:
1. Incorrect API token in config.yml
2. Missing permissions for pve_exporter user
3. Port 9223 is already in use
4. Proxmox API is not accessible
Check logs above for details.
when: port_check.failed