prometheus: Use os packaged prometheus

This commit is contained in:
Timo Makinen 2023-11-04 20:36:10 +00:00
parent 7ee84bffd9
commit 929738af88
4 changed files with 30 additions and 74 deletions

View file

@ -1,23 +0,0 @@
[Unit]
Description=Prometheus
After=network-online.target
Requires=local-fs.target
After=local-fs.target
[Service]
Type=simple
Environment="GOMAXPROCS={{ ansible_processor_vcpus|default(ansible_processor_count) }}"
User=prometheus
Group=prometheus
UMask=007
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/sbin/prometheus \
--config.file=/srv/prometheus/prometheus.yml \
--log.level=info \
--storage.tsdb.path=/srv/prometheus/data \
--storage.tsdb.retention.time=365d \
--web.console.libraries=/usr/local/share/prometheus/console_libraries
Restart=always
[Install]
WantedBy=multi-user.target

View file

@ -1,3 +1,4 @@
---
dependencies:
- {role: epel_repo}
- {role: nginx}

View file

@ -14,43 +14,18 @@
shell: /sbin/nologin
uid: 305
- name: Extract package
ansible.builtin.unarchive:
src: >-
{{
"https://github.com/prometheus/prometheus/releases/download/v" +
prometheus_version + "/prometheus-" + prometheus_version +
".linux-amd64.tar.gz"
}}
dest: /usr/local/src
owner: root
group: "{{ ansible_wheel }}"
remote_src: true
- name: Install packages
ansible.builtin.package:
name: golang-github-prometheus
state: installed
- name: Copy binaries
ansible.builtin.copy:
dest: "/usr/local/sbin/{{ item }}"
src: >-
/usr/local/src/prometheus-{{ prometheus_version }}.linux-amd64/{{ item }}
mode: "0755"
owner: root
group: "{{ ansible_wheel }}"
remote_src: true
notify: Restart prometheus
with_items:
- promtool
- prometheus
- name: Create data directories
- name: Create data directory
ansible.builtin.file:
path: "{{ item }}"
path: /export/prometheus
state: directory
mode: "0750"
mode: "0770"
owner: root
group: prometheus
with_items:
- /export/prometheus
- /export/prometheus/node.d
- name: Link data directory
ansible.builtin.file:
@ -61,26 +36,38 @@
group: "{{ ansible_wheel }}"
follow: false
- name: Create database directory
ansible.builtin.file:
path: /srv/prometheus/data
state: directory
mode: "0770"
owner: root
group: prometheus
- name: Configure startup options
ansible.builtin.lineinfile:
path: /etc/default/prometheus
regexp: "^ARGS="
line: >-
ARGS="--config.file=/etc/prometheus/prometheus.yml
--log.level=info
--storage.tsdb.path=/srv/prometheus
--storage.tsdb.retention.time=365d
--web.console.libraries=/usr/local/share/prometheus/console_libraries"
notify: Restart prometheus
- name: Create configuration
ansible.builtin.template:
dest: /srv/prometheus/prometheus.yml
dest: /etc/prometheus/prometheus.yml
src: prometheus.yml.j2
mode: "0640"
owner: root
group: prometheus
notify: Restart prometheus
- name: Create host config directory
ansible.builtin.file:
path: /etc/prometheus/node.d
state: directory
mode: "0750"
owner: root
group: prometheus
- name: Create host configs
ansible.builtin.template:
dest: "/srv/prometheus/node.d/{{ item }}.json"
dest: "/etc/prometheus/node.d/{{ item }}.json"
src: node.json.j2
mode: "0640"
owner: root
@ -88,15 +75,6 @@
notify: Restart prometheus
with_items: "{{ groups['all'] }}"
- name: Create service file
ansible.builtin.copy:
dest: /etc/systemd/system/prometheus.service
src: prometheus.service
mode: "0644"
owner: root
group: "{{ ansible_wheel }}"
notify: Restart prometheus
- name: Enable service
ansible.builtin.service:
name: prometheus

View file

@ -13,4 +13,4 @@ scrape_configs:
cert_file: "{{ tls_certs }}/{{ inventory_hostname }}.crt"
file_sd_configs:
- files:
- /srv/prometheus/node.d/*.json
- /etc/prometheus/node.d/*.json