add prometheus role
This commit is contained in:
84
roles/prometheus/tasks/install.yml
Normal file
84
roles/prometheus/tasks/install.yml
Normal file
@@ -0,0 +1,84 @@
|
||||
---
|
||||
- name: "Create Prometheus system group"
|
||||
ansible.builtin.group:
|
||||
name: "{{ prometheus_group }}"
|
||||
system: true
|
||||
state: present
|
||||
|
||||
- name: "Create Prometheus system user"
|
||||
ansible.builtin.user:
|
||||
name: "{{ prometheus_user }}"
|
||||
group: "{{ prometheus_group }}"
|
||||
system: true
|
||||
shell: "/sbin/nologin"
|
||||
create_home: false
|
||||
state: present
|
||||
|
||||
- name: "Install prometheus from binary"
|
||||
block:
|
||||
- name: "Check Prometheus version"
|
||||
changed_when: false
|
||||
ansible.builtin.command:
|
||||
cmd: "prometheus --version"
|
||||
register: prometheus_ver
|
||||
|
||||
- name: "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: "Create prometheus directories {{ item }}"
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
owner: "{{ prometheus_user }}"
|
||||
group: "{{ prometheus_group }}"
|
||||
mode: "0755"
|
||||
with_items:
|
||||
- "{{ config_dir }}"
|
||||
- "{{ prometheus_dir }}"
|
||||
- "{{ db_dir }}"
|
||||
|
||||
- name: "Download Prometheus binary"
|
||||
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_user }}"
|
||||
group: "{{ prometheus_group }}"
|
||||
mode: "0644"
|
||||
|
||||
- name: "Unpack Prometheus binaries"
|
||||
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: "Cleanup downloaded file"
|
||||
ansible.builtin.file:
|
||||
path: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
||||
state: absent
|
||||
|
||||
- name: "Move official prometheus and promtool binaries"
|
||||
ansible.builtin.copy:
|
||||
src: "{{ prometheus_dir }}/prometheus-{{ prometheus_version }}.linux-amd64/{{ item }}"
|
||||
dest: "/usr/local/bin/{{ item }}"
|
||||
mode: "0755"
|
||||
owner: "{{ prometheus_user }}"
|
||||
group: "{{ prometheus_group }}"
|
||||
remote_src: true
|
||||
with_items:
|
||||
- prometheus
|
||||
- promtool
|
||||
|
||||
- name: "Create systemd service unit"
|
||||
notify: "(Re)start Prometheus service"
|
||||
ansible.builtin.template:
|
||||
src: prometheus.service.j2
|
||||
dest: /etc/systemd/system/prometheus.service
|
||||
owner: "{{ prometheus_user }}"
|
||||
group: "{{ prometheus_group }}"
|
||||
mode: "0660"
|
||||
Reference in New Issue
Block a user