security_ansible_playbook/roles/promotheus/tasks/main.yaml

73 lines
1.5 KiB
YAML

---
- name: Update apt cache
apt:
update_cache: yes
- name: Install Prometheus from Ubuntu repository
apt:
name:
- prometheus
- prometheus-node-exporter
state: present
- name: Check which Prometheus services are available
shell: systemctl list-unit-files | grep prometheus
register: prometheus_services
ignore_errors: true
- name: Debug available Prometheus services
debug:
var: prometheus_services.stdout_lines
- name: Generate Prometheus configuration
template:
src: prometheus.yml.j2
dest: /etc/prometheus/prometheus.yml
owner: prometheus
group: prometheus
mode: '0644'
backup: yes
notify: restart prometheus
- name: Start and enable Prometheus service (try different service names)
service:
name: "{{ item }}"
state: started
enabled: yes
loop:
- prometheus
- prometheus-server
ignore_errors: true
register: service_start_result
- name: Debug service start results
debug:
var: service_start_result
- name: Start and enable Node Exporter
service:
name: prometheus-node-exporter
state: started
enabled: yes
ignore_errors: true
- name: Check Prometheus status
shell: systemctl status prometheus* --no-pager
register: prometheus_status
ignore_errors: true
- name: Show Prometheus status
debug:
var: prometheus_status.stdout_lines
- name: Check if Prometheus is listening on port 9090
wait_for:
port: 9090
host: 127.0.0.1
timeout: 30
ignore_errors: true
register: port_check
- name: Debug port check
debug:
var: port_check