78 lines
2.6 KiB
YAML
78 lines
2.6 KiB
YAML
---
|
|
- name: "Install | Create Prometheus system user"
|
|
ansible.builtin.user:
|
|
name: "prometheus"
|
|
system: true
|
|
shell: "/sbin/nologin"
|
|
create_home: false
|
|
state: present
|
|
|
|
- name: "Install | Install the binary"
|
|
block:
|
|
- name: "Install | Check Prometheus version"
|
|
changed_when: false
|
|
ansible.builtin.command:
|
|
cmd: "prometheus --version"
|
|
register: prometheus_ver
|
|
|
|
- name: "Install | Assert version correctness"
|
|
ansible.builtin.assert:
|
|
that: "prometheus_ver.stdout is regex('{{ prometheus_version }}')"
|
|
success_msg: "prometheus version {{ prometheus_version }} is installed and working"
|
|
fail_msg: "prometheus version {{ prometheus_version }} is not installed or not working correctly"
|
|
|
|
rescue:
|
|
- name: "Install | Create directories {{ item }}"
|
|
with_items:
|
|
- "{{ prometheus_config_dir }}"
|
|
- "{{ prometheus_config_dir }}/rules"
|
|
- "{{ prometheus_db_dir }}"
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
owner: "prometheus"
|
|
group: "prometheus"
|
|
mode: "0755"
|
|
|
|
- name: "Install | Download the binary distribution"
|
|
ansible.builtin.get_url:
|
|
url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
|
dest: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
|
owner: "prometheus"
|
|
group: "prometheus"
|
|
mode: "0644"
|
|
|
|
- name: "Install | Unpack the distribution"
|
|
notify: "(Re)start Prometheus service"
|
|
ansible.builtin.unarchive:
|
|
src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
|
dest: "{{ prometheus_dir }}"
|
|
creates: "{{ prometheus_dir }}/prometheus-{{ prometheus_version }}.linux-amd64"
|
|
remote_src: true
|
|
|
|
- name: "Install | Clean up downloads"
|
|
ansible.builtin.file:
|
|
path: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
|
state: absent
|
|
|
|
- name: "Install | Move official prometheus and promtool binaries"
|
|
with_items:
|
|
- prometheus
|
|
- promtool
|
|
ansible.builtin.copy:
|
|
src: "{{ prometheus_dir }}/prometheus-{{ prometheus_version }}.linux-amd64/{{ item }}"
|
|
dest: "/usr/local/bin/{{ item }}"
|
|
mode: "0755"
|
|
owner: "prometheus"
|
|
group: "prometheus"
|
|
remote_src: true
|
|
|
|
- name: "Install | Create a systemd service unit"
|
|
notify: "(Re)start Prometheus service"
|
|
ansible.builtin.template:
|
|
src: prometheus.service.j2
|
|
dest: /etc/systemd/system/prometheus.service
|
|
owner: "prometheus"
|
|
group: "prometheus"
|
|
mode: "0660"
|