Merge pull request #73 from corvus-migratorius/fix-prometheus
Fix Prometheus
This commit is contained in:
@@ -1,7 +1,4 @@
|
|||||||
---
|
---
|
||||||
prometheus_version: 3.2.1
|
prometheus_version: "3.5.0"
|
||||||
prometheus_dir: "/etc/prometheus"
|
prometheus_config_dir: "/etc/prometheus"
|
||||||
prometheus_user: prometheus
|
|
||||||
prometheus_group: prometheus
|
|
||||||
prometheus_config_dir: "/etc/prometheus/conf"
|
|
||||||
prometheus_db_dir: "/var/lib/prometheus"
|
prometheus_db_dir: "/var/lib/prometheus"
|
||||||
|
|||||||
@@ -5,4 +5,4 @@
|
|||||||
roles:
|
roles:
|
||||||
- role: genlab.common.prometheus
|
- role: genlab.common.prometheus
|
||||||
prometheus_config_source_dir: prometheus
|
prometheus_config_source_dir: prometheus
|
||||||
alertrules_source_dir: prometheus/rules
|
prometheus_alertrules_source_dir: prometheus/rules
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
- name: "Check Prometheus version"
|
- name: "Check Prometheus version"
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that: "prometheus_installed_version.stdout is regex('{{ prometheus_version }}')"
|
that: "prometheus_installed_version.stdout is regex('{{ prometheus_version }}')"
|
||||||
success_msg: "Prometheus version {{ prometheus_version }} is installed and working"
|
success_msg: "Prometheus version {{ prometheus_version }} is available and executable"
|
||||||
fail_msg: "Prometheus version {{ prometheus_version }} is not installed or not working correctly"
|
fail_msg: "Prometheus version {{ prometheus_version }} not found or not executable"
|
||||||
|
|
||||||
# kics-scan ignore-block
|
# kics-scan ignore-block
|
||||||
- name: "Check if Prometheus is reachable"
|
- name: "Check if Prometheus is reachable"
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
---
|
---
|
||||||
- name: "Copy config file"
|
- name: "Configure | Copy Prometheus configuration files"
|
||||||
notify: "(Re)start Prometheus service"
|
notify: "(Re)start Prometheus service"
|
||||||
ansible.builtin.copy:
|
|
||||||
src: "{{ item }}"
|
|
||||||
dest: "{{ prometheus_config_dir }}/{{ item | basename }}"
|
|
||||||
owner: "{{ prometheus_user }}"
|
|
||||||
group: "{{ prometheus_group }}"
|
|
||||||
mode: "0660"
|
|
||||||
with_fileglob:
|
with_fileglob:
|
||||||
- "{{ prometheus_config_source_dir }}/*.yml"
|
- "{{ prometheus_config_source_dir }}/*.yml"
|
||||||
|
|
||||||
- name: "Copy alert rules"
|
|
||||||
notify: "(Re)start Prometheus service"
|
|
||||||
when: alertrules_source_dir is defined
|
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: "{{ item }}"
|
src: "{{ item }}"
|
||||||
dest: "{{ prometheus_config_dir }}/{{ item | basename }}"
|
dest: "{{ prometheus_config_dir }}/{{ item | basename }}"
|
||||||
owner: "{{ prometheus_user }}"
|
owner: "prometheus"
|
||||||
group: "{{ prometheus_group }}"
|
group: "prometheus"
|
||||||
mode: "0660"
|
mode: "0660"
|
||||||
|
|
||||||
|
- name: "Configure | Copy alert rules"
|
||||||
|
notify: "(Re)start Prometheus service"
|
||||||
|
when: prometheus_alertrules_source_dir is defined
|
||||||
with_fileglob:
|
with_fileglob:
|
||||||
- "{{ alertrules_source_dir }}/*.yml"
|
- "{{ prometheus_alertrules_source_dir }}/*.yml"
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: "{{ item }}"
|
||||||
|
dest: "{{ prometheus_config_dir }}/rules/{{ item | basename }}"
|
||||||
|
owner: "prometheus"
|
||||||
|
group: "prometheus"
|
||||||
|
mode: "0660"
|
||||||
|
|||||||
@@ -1,84 +1,69 @@
|
|||||||
---
|
---
|
||||||
- name: "Create Prometheus system group"
|
- name: "Install | Create Prometheus system user"
|
||||||
ansible.builtin.group:
|
|
||||||
name: "{{ prometheus_group }}"
|
|
||||||
system: true
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: "Create Prometheus system user"
|
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: "{{ prometheus_user }}"
|
name: "prometheus"
|
||||||
group: "{{ prometheus_group }}"
|
|
||||||
system: true
|
system: true
|
||||||
shell: "/sbin/nologin"
|
shell: "/sbin/nologin"
|
||||||
create_home: false
|
create_home: false
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: "Install prometheus from binary"
|
- name: "Install | Install the binary"
|
||||||
block:
|
block:
|
||||||
- name: "Check Prometheus version"
|
- name: "Install | Check Prometheus version"
|
||||||
changed_when: false
|
changed_when: false
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: "prometheus --version"
|
cmd: "prometheus --version"
|
||||||
register: prometheus_ver
|
register: prometheus_ver
|
||||||
|
|
||||||
- name: "Assert version correctness"
|
- name: "Install | Assert version correctness"
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that: "prometheus_ver.stdout is regex('{{ prometheus_version }}')"
|
that: "prometheus_ver.stdout is regex('{{ prometheus_version }}')"
|
||||||
success_msg: "prometheus version {{ prometheus_version }} is installed and working"
|
success_msg: "prometheus version {{ prometheus_version }} is installed and working"
|
||||||
fail_msg: "prometheus version {{ prometheus_version }} is not installed or not working correctly"
|
fail_msg: "prometheus version {{ prometheus_version }} is not installed or not working correctly"
|
||||||
|
|
||||||
rescue:
|
rescue:
|
||||||
- name: "Create prometheus directories {{ item }}"
|
- name: "Install | Create directories {{ item }}"
|
||||||
|
with_items:
|
||||||
|
- "{{ prometheus_config_dir }}"
|
||||||
|
- "{{ prometheus_config_dir }}/rules"
|
||||||
|
- "{{ prometheus_db_dir }}"
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
state: directory
|
state: directory
|
||||||
owner: "{{ prometheus_user }}"
|
owner: "prometheus"
|
||||||
group: "{{ prometheus_group }}"
|
group: "prometheus"
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
with_items:
|
|
||||||
- "{{ prometheus_config_dir }}"
|
|
||||||
- "{{ prometheus_dir }}"
|
|
||||||
- "{{ prometheus_db_dir }}"
|
|
||||||
|
|
||||||
- name: "Download Prometheus binary"
|
- name: "Install | Fetch and unpack the 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_user }}"
|
|
||||||
group: "{{ prometheus_group }}"
|
|
||||||
mode: "0644"
|
|
||||||
|
|
||||||
- name: "Unpack Prometheus binaries"
|
|
||||||
notify: "(Re)start Prometheus service"
|
notify: "(Re)start Prometheus service"
|
||||||
ansible.builtin.unarchive:
|
ansible.builtin.unarchive:
|
||||||
src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
src: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
|
||||||
dest: "{{ prometheus_dir }}"
|
dest: "/tmp"
|
||||||
creates: "{{ prometheus_dir }}/prometheus-{{ prometheus_version }}.linux-amd64"
|
creates: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64"
|
||||||
remote_src: true
|
remote_src: true
|
||||||
|
|
||||||
- name: "Cleanup downloaded file"
|
- name: "Install | Put the binaries under the PATH"
|
||||||
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:
|
with_items:
|
||||||
- prometheus
|
- prometheus
|
||||||
- promtool
|
- promtool
|
||||||
|
ansible.builtin.copy:
|
||||||
|
remote_src: true
|
||||||
|
src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/{{ item }}"
|
||||||
|
dest: "/usr/bin/{{ item }}"
|
||||||
|
owner: "prometheus"
|
||||||
|
group: "prometheus"
|
||||||
|
mode: "0755"
|
||||||
|
|
||||||
- name: "Create systemd service unit"
|
- name: "Install | Clean up the downloads"
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: "Install | Create a systemd service unit"
|
||||||
notify: "(Re)start Prometheus service"
|
notify: "(Re)start Prometheus service"
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: prometheus.service.j2
|
src: prometheus.service.j2
|
||||||
dest: /etc/systemd/system/prometheus.service
|
dest: /etc/systemd/system/prometheus.service
|
||||||
owner: "{{ prometheus_user }}"
|
owner: "prometheus"
|
||||||
group: "{{ prometheus_group }}"
|
group: "prometheus"
|
||||||
mode: "0660"
|
mode: "0660"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Documentation="https://prometheus.io/"
|
|||||||
User=prometheus
|
User=prometheus
|
||||||
Group=prometheus
|
Group=prometheus
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/usr/local/bin/prometheus \
|
ExecStart=/usr/bin/prometheus \
|
||||||
--config.file {{ prometheus_config_dir }}/prometheus.yml \
|
--config.file {{ prometheus_config_dir }}/prometheus.yml \
|
||||||
--storage.tsdb.path {{ prometheus_db_dir }} \
|
--storage.tsdb.path {{ prometheus_db_dir }} \
|
||||||
--storage.tsdb.retention.time=30d
|
--storage.tsdb.retention.time=30d
|
||||||
|
|||||||
Reference in New Issue
Block a user