prometheus/tasks/exporter/_common.yml

131 lines
5.0 KiB
YAML
Raw Normal View History

2022-11-11 23:51:52 +01:00
---
# to build prometheus repo for another var: https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#when-should-i-use-also-how-to-interpolate-variables-or-dynamic-variable-names
- set_fact:
prometheus_repo: "{{ lookup('vars', 'prometheus_repo_' ~ exporter) }}"
#- name: debug
# debug:
# msg: "Repo: {{ prometheus_repo }}"
- name: '{{ exporter }} exporter | check if exporter is already install'
stat:
path: /usr/local/bin/prometheus-{{ exporter }}-exporter
register: stat_result
tags: [ 'prometheus_{{ exporter }}' ]
2022-11-14 10:58:21 +01:00
- name: '{{ exporter }} exporter | stop old version'
2022-11-11 23:51:52 +01:00
systemd:
name: prometheus-{{ exporter }}-exporter.service
state: stopped
when: exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]
2022-11-14 10:58:21 +01:00
- name: '{{ exporter }} exporter | remove old version'
2022-11-11 23:51:52 +01:00
file:
path: /usr/local/bin/prometheus-{{ exporter }}-exporter
state: absent
when: exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]
2023-07-20 11:47:31 +02:00
# If prometheus_exporters_sources == "repo"
- name: '{{ exporter }} exporter | download from repo'
get_url:
url: "{{prometheus_exporters_repo}}/releases/download/{{prometheus_exporters_release}}/{{exporter}}_exporter"
dest: /usr/local/bin/prometheus-{{ exporter }}-exporter
remote_src: yes
owner: root
group: root
mode: 0755
ignore_errors: '{{ ansible_check_mode }}'
when: >
(not stat_result.stat.exists or exporter_upgrade == "yes") and
prometheus_exporters_sources == "repo"
tags: [ 'prometheus_{{ exporter }}' ]
# If prometheus_exporters_sources == "origin"
2022-11-11 23:51:52 +01:00
- name: '{{ exporter }} exporter | create temp path'
file:
state: directory
path: /tmp/prometheus_exporter/{{ exporter }}
2023-07-20 11:47:31 +02:00
when: >
2023-07-20 11:50:47 +02:00
(not stat_result.stat.exists or exporter_upgrade == "yes") and
2023-07-20 11:47:31 +02:00
prometheus_exporters_sources == "origin"
2022-11-11 23:51:52 +01:00
tags: [ 'prometheus_{{ exporter }}' ]
2022-11-14 11:05:19 +01:00
- name: '{{ exporter }} exporter | get latest release from GitHub'
2022-11-11 23:51:52 +01:00
shell: curl --silent "https://api.github.com/repos/{{ prometheus_repo }}/{{ exporter }}_exporter/releases/latest" | jq -r .tag_name | sed "s/v//"
register: prometheus_exporter_latest_version
run_once: true
2023-07-20 11:47:31 +02:00
when: >
(not stat_result.stat.exists or exporter_upgrade == "yes") and
prometheus_exporters_sources == "origin"
2022-11-11 23:51:52 +01:00
tags: [ 'prometheus_{{ exporter }}' ]
2023-07-20 11:47:31 +02:00
- name: '{{ exporter }} exporter | download from origin'
2022-11-11 23:51:52 +01:00
get_url:
url: "https://github.com/{{ prometheus_repo }}/{{ exporter }}_exporter/releases/download/v{{ prometheus_exporter_latest_version.stdout }}/{{ exporter }}_exporter-{{ prometheus_exporter_latest_version.stdout }}.{{ prometheus_os }}-{{ prometheus_arch }}.tar.gz"
dest: /tmp/prometheus_exporter/{{ exporter }}/
2023-02-10 14:16:27 +01:00
ignore_errors: '{{ ansible_check_mode }}'
2023-07-20 11:47:31 +02:00
when: >
(not stat_result.stat.exists or exporter_upgrade == "yes") and
prometheus_exporters_sources == "origin"
2022-11-11 23:51:52 +01:00
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | unarchive'
unarchive:
remote_src: yes
src: /tmp/prometheus_exporter/{{ exporter }}/{{ exporter }}_exporter-{{ prometheus_exporter_latest_version.stdout }}.{{ prometheus_os }}-{{ prometheus_arch }}.tar.gz
dest: /tmp/prometheus_exporter/{{ exporter }}/
2023-07-20 11:47:31 +02:00
when: >
(not stat_result.stat.exists or exporter_upgrade == "yes") and
prometheus_exporters_sources == "origin"
2023-02-10 14:16:27 +01:00
ignore_errors: '{{ ansible_check_mode }}'
2022-11-11 23:51:52 +01:00
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | move to /usr/local/bin'
copy:
src: /tmp/prometheus_exporter/{{ exporter }}/{{ exporter }}_exporter-{{ prometheus_exporter_latest_version.stdout }}.{{ prometheus_os }}-{{ prometheus_arch }}/{{ exporter }}_exporter
dest: /usr/local/bin/prometheus-{{ exporter }}-exporter
remote_src: yes
owner: root
group: root
mode: 0755
notify:
2023-02-10 11:13:37 +01:00
- '{{ exporter }}-exporter-restart'
2023-07-20 11:47:31 +02:00
when: >
(not stat_result.stat.exists or exporter_upgrade == "yes") and
prometheus_exporters_sources == "origin"
2022-11-11 23:51:52 +01:00
tags: [ 'prometheus_{{ exporter }}' ]
2023-02-10 14:16:27 +01:00
ignore_errors: '{{ ansible_check_mode }}'
2022-11-11 23:51:52 +01:00
- name: '{{ exporter }} exporter | cleanup temp path'
file:
state: absent
path: /tmp/prometheus_exporter/{{ exporter }}
2023-07-20 11:47:31 +02:00
when: >
(not stat_result.stat.exists or exporter_upgrade == "yes") and
prometheus_exporters_sources == "origin"
2022-11-11 23:51:52 +01:00
- name: '{{ exporter }} exporter | systemd | copy unit file'
template:
2022-11-14 10:58:21 +01:00
src: systemd/prometheus-{{ exporter }}-exporter.service.j2
2022-11-11 23:51:52 +01:00
dest: /etc/systemd/system/prometheus-{{ exporter }}-exporter.service
owner: root
group: root
mode: 0600
notify:
2023-02-10 11:13:37 +01:00
- '{{ exporter }}-exporter-restart'
2022-11-11 23:51:52 +01:00
when: not stat_result.stat.exists or exporter_upgrade == "yes"
2023-02-10 14:16:27 +01:00
ignore_errors: '{{ ansible_check_mode }}'
2022-11-11 23:51:52 +01:00
tags: [ 'prometheus_{{ exporter }}' ]
2023-01-27 20:33:56 +01:00
- name: '{{ exporter }} exporter | systemd | enable service'
2022-11-11 23:51:52 +01:00
systemd:
daemon_reload: yes
enabled: yes
name: prometheus-{{ exporter }}-exporter.service
ignore_errors: '{{ ansible_check_mode }}'
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]