add the ansible playbooks for the monitoring stack
This commit is contained in:
82
ansible/roles/prometheus/tasks/main.yml
Normal file
82
ansible/roles/prometheus/tasks/main.yml
Normal file
@@ -0,0 +1,82 @@
|
||||
---
|
||||
- name: Create Prometheus directories
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
owner: monitoring
|
||||
group: monitoring
|
||||
mode: "0755"
|
||||
loop:
|
||||
- /etc/prometheus
|
||||
- /var/lib/prometheus
|
||||
|
||||
- name: Check if Prometheus is installed
|
||||
ansible.builtin.stat:
|
||||
path: /usr/local/bin/prometheus
|
||||
register: prometheus_binary
|
||||
|
||||
- name: Get installed Prometheus version
|
||||
ansible.builtin.command: /usr/local/bin/prometheus --version
|
||||
register: prometheus_installed_version
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
when: prometheus_binary.stat.exists
|
||||
|
||||
- name: Download Prometheus
|
||||
ansible.builtin.get_url:
|
||||
url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-{{ go_arch }}.tar.gz"
|
||||
dest: "/tmp/prometheus-{{ prometheus_version }}.tar.gz"
|
||||
mode: "0644"
|
||||
when: not prometheus_binary.stat.exists or prometheus_version not in (prometheus_installed_version.stdout | default(''))
|
||||
|
||||
- name: Extract Prometheus
|
||||
ansible.builtin.unarchive:
|
||||
src: "/tmp/prometheus-{{ prometheus_version }}.tar.gz"
|
||||
dest: /tmp
|
||||
remote_src: true
|
||||
when: not prometheus_binary.stat.exists or prometheus_version not in (prometheus_installed_version.stdout | default(''))
|
||||
|
||||
- name: Install Prometheus binaries
|
||||
ansible.builtin.copy:
|
||||
src: "/tmp/prometheus-{{ prometheus_version }}.linux-{{ go_arch }}/{{ item }}"
|
||||
dest: "/usr/local/bin/{{ item }}"
|
||||
mode: "0755"
|
||||
remote_src: true
|
||||
loop:
|
||||
- prometheus
|
||||
- promtool
|
||||
notify: Restart prometheus
|
||||
when: not prometheus_binary.stat.exists or prometheus_version not in (prometheus_installed_version.stdout | default(''))
|
||||
|
||||
- name: Deploy Prometheus configuration
|
||||
ansible.builtin.template:
|
||||
src: prometheus.yml.j2
|
||||
dest: /etc/prometheus/prometheus.yml
|
||||
owner: monitoring
|
||||
group: monitoring
|
||||
mode: "0644"
|
||||
notify: Restart prometheus
|
||||
|
||||
- name: Deploy Prometheus systemd service
|
||||
ansible.builtin.template:
|
||||
src: prometheus.service.j2
|
||||
dest: /etc/systemd/system/prometheus.service
|
||||
mode: "0644"
|
||||
notify:
|
||||
- Reload systemd
|
||||
- Restart prometheus
|
||||
|
||||
- name: Enable and start Prometheus
|
||||
ansible.builtin.systemd:
|
||||
name: prometheus
|
||||
enabled: true
|
||||
state: started
|
||||
daemon_reload: true
|
||||
|
||||
- name: Clean up downloaded files
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- "/tmp/prometheus-{{ prometheus_version }}.tar.gz"
|
||||
- "/tmp/prometheus-{{ prometheus_version }}.linux-{{ go_arch }}"
|
||||
Reference in New Issue
Block a user