From 902af9c58dba3f05e67f540033ba172613812313 Mon Sep 17 00:00:00 2001 From: "tom.chivert" Date: Thu, 20 Jul 2023 11:47:31 +0200 Subject: [PATCH] add new exporters binaries source --- defaults/main.yml | 5 +++++ tasks/exporter/_common.yml | 41 ++++++++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 5eb25d4..ea9c420 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -26,6 +26,11 @@ prometheus_repo_postgres: prometheus-community prometheus_repo_redis: tchivert prometheus_repo_varnish: tchivert +prometheus_exporters_repo: "https://git.rznet.fr/tchivert/prometheus_exporters" +prometheus_exporters_release: "latest" +prometheus_exporters_sources: "repo" +# prometheus_exporters_sources: "origin" + ## server prometheus_nodes_ip: localhost: "127.0.0.1" diff --git a/tasks/exporter/_common.yml b/tasks/exporter/_common.yml index 5c2f901..33e6d6e 100644 --- a/tasks/exporter/_common.yml +++ b/tasks/exporter/_common.yml @@ -28,26 +28,48 @@ when: exporter_upgrade == "yes" tags: [ 'prometheus_{{ exporter }}' ] +# 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" - name: '{{ exporter }} exporter | create temp path' file: state: directory path: /tmp/prometheus_exporter/{{ exporter }} - when: not stat_result.stat.exists or exporter_upgrade == "yes" + when: > + not stat_result.stat.exists or exporter_upgrade == "yes" + prometheus_exporters_sources == "origin" tags: [ 'prometheus_{{ exporter }}' ] - name: '{{ exporter }} exporter | get latest release from GitHub' 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 - when: not stat_result.stat.exists or exporter_upgrade == "yes" + when: > + (not stat_result.stat.exists or exporter_upgrade == "yes") and + prometheus_exporters_sources == "origin" tags: [ 'prometheus_{{ exporter }}' ] -- name: '{{ exporter }} exporter | download' +- name: '{{ exporter }} exporter | download from origin' 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 }}/ ignore_errors: '{{ ansible_check_mode }}' - when: not stat_result.stat.exists or exporter_upgrade == "yes" + when: > + (not stat_result.stat.exists or exporter_upgrade == "yes") and + prometheus_exporters_sources == "origin" tags: [ 'prometheus_{{ exporter }}' ] - name: '{{ exporter }} exporter | unarchive' @@ -55,7 +77,9 @@ 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 }}/ - when: not stat_result.stat.exists or exporter_upgrade == "yes" + when: > + (not stat_result.stat.exists or exporter_upgrade == "yes") and + prometheus_exporters_sources == "origin" ignore_errors: '{{ ansible_check_mode }}' tags: [ 'prometheus_{{ exporter }}' ] @@ -69,7 +93,9 @@ mode: 0755 notify: - '{{ exporter }}-exporter-restart' - when: not stat_result.stat.exists or exporter_upgrade == "yes" + when: > + (not stat_result.stat.exists or exporter_upgrade == "yes") and + prometheus_exporters_sources == "origin" tags: [ 'prometheus_{{ exporter }}' ] ignore_errors: '{{ ansible_check_mode }}' @@ -77,6 +103,9 @@ file: state: absent path: /tmp/prometheus_exporter/{{ exporter }} + when: > + (not stat_result.stat.exists or exporter_upgrade == "yes") and + prometheus_exporters_sources == "origin" - name: '{{ exporter }} exporter | systemd | copy unit file' template: