From daac4303b08dfc102ca510d8196dc596ee272eba Mon Sep 17 00:00:00 2001 From: Ludovic Cartier Date: Mon, 31 May 2021 15:42:33 +0200 Subject: [PATCH] add custom exporter's version support --- tasks/mongodb_exporter.yml | 25 ++++++++++++++++++++----- tasks/mysqld_exporter.yml | 8 ++++---- tasks/node_exporter.yml | 6 +++--- tasks/postgresql_exporter.yml | 6 +++--- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/tasks/mongodb_exporter.yml b/tasks/mongodb_exporter.yml index 46612ad..f69baf1 100644 --- a/tasks/mongodb_exporter.yml +++ b/tasks/mongodb_exporter.yml @@ -3,23 +3,23 @@ shell: curl --silent "https://api.github.com/repos/percona/mongodb_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" args: warn: false - register: prometheus_mongodb_exporter_version + register: prometheus_mongodb_exporter_latest_version run_once: true - name: 'prometheus | mongodb exporter | download' get_url: - url: https://github.com/percona/mongodb_exporter/releases/download/v{{ prometheus_mongodb_exporter_version.stdout }}/mongodb_exporter-{{ prometheus_mongodb_exporter_version.stdout }}.linux-amd64.tar.gz + url: https://github.com/percona/mongodb_exporter/releases/download/v{{ prometheus_mongodb_exporter_version|default(prometheus_mongodb_exporter_latest_version.stdout) }}/mongodb_exporter-{{ prometheus_mongodb_exporter_version|default(prometheus_mongodb_exporter_latest_version.stdout) }}.linux-amd64.tar.gz dest: /tmp - name: 'prometheus | mongodb exporter | unarchive' unarchive: remote_src: yes - src: /tmp/mongodb_exporter-{{ prometheus_mongodb_exporter_version.stdout }}.linux-amd64.tar.gz + src: /tmp/mongodb_exporter-{{ prometheus_mongodb_exporter_version|default(prometheus_mongodb_exporter_latest_version.stdout) }}.linux-amd64.tar.gz dest: /tmp -- name: 'prometheus | mongodb exporter | move to /usr/local/bin' +- name: 'prometheus | mongodb exporter < v0.2 | move to /usr/local/bin' copy: - src: /tmp/mongodb_exporter-{{ prometheus_mongodb_exporter_version.stdout }}.linux-amd64/mongodb_exporter + src: /tmp/mongodb_exporter dest: /usr/local/bin/prometheus-mongodb-exporter remote_src: yes owner: root @@ -27,6 +27,21 @@ mode: 0755 notify: - 'prometheus | mongodb exporter | restart service' + when: + - prometheus_mongodb_exporter_version < '0.2' + +- name: 'prometheus | mongodb exporter > v0.2 | move to /usr/local/bin' + copy: + src: /tmp/mongodb_exporter-{{ prometheus_mongodb_exporter_version|default(prometheus_mongodb_exporter_latest_version.stdout) }}.linux-amd64/mongodb_exporter + dest: /usr/local/bin/prometheus-mongodb-exporter + remote_src: yes + owner: root + group: root + mode: 0755 + notify: + - 'prometheus | mongodb exporter | restart service' + when: + - prometheus_mongodb_exporter_version > '0.2' - name: 'prometheus | mongodb exporter | install unit file to systemd' template: diff --git a/tasks/mysqld_exporter.yml b/tasks/mysqld_exporter.yml index 56f0bf3..13de1f3 100644 --- a/tasks/mysqld_exporter.yml +++ b/tasks/mysqld_exporter.yml @@ -3,23 +3,23 @@ shell: curl --silent "https://api.github.com/repos/prometheus/mysqld_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" args: warn: false - register: prometheus_mysqld_exporter_version + register: prometheus_mysqld_exporter_latest_version run_once: true - name: 'prometheus | mysqld exporter | download' get_url: - url: https://github.com/prometheus/mysqld_exporter/releases/download/v{{ prometheus_mysqld_exporter_version.stdout }}/mysqld_exporter-{{ prometheus_mysqld_exporter_version.stdout }}.linux-amd64.tar.gz + url: https://github.com/prometheus/mysqld_exporter/releases/download/v{{ prometheus_mysqld_exporter_version|default(prometheus_mysqld_exporter_latest_version.stdout) }}/mysqld_exporter-{{ prometheus_mysqld_exporter_version.|default(prometheus_mysqld_exporter_latest_version.stdout) }}.linux-amd64.tar.gz dest: /tmp - name: 'prometheus | mysqld exporter | unarchive' unarchive: remote_src: yes - src: /tmp/mysqld_exporter-{{ prometheus_mysqld_exporter_version.stdout }}.linux-amd64.tar.gz + src: /tmp/mysqld_exporter-{{ prometheus_mysqld_exporter_version|default(prometheus_mysqld_exporter_latest_version.stdout) }}.linux-amd64.tar.gz dest: /tmp - name: 'prometheus | mysqld exporter | move to /usr/local/bin' copy: - src: /tmp/mysqld_exporter-{{ prometheus_mysqld_exporter_version.stdout }}.linux-amd64/mysqld_exporter + src: /tmp/mysqld_exporter-{{ prometheus_mysqld_exporter_version|default(prometheus_mysqld_exporter_latest_version.stdout) }}.linux-amd64/mysqld_exporter dest: /usr/local/bin/prometheus-mysqld-exporter remote_src: yes owner: root diff --git a/tasks/node_exporter.yml b/tasks/node_exporter.yml index 057d324..468f559 100644 --- a/tasks/node_exporter.yml +++ b/tasks/node_exporter.yml @@ -8,18 +8,18 @@ - name: 'prometheus | node exporter | download' get_url: - url: https://github.com/prometheus/node_exporter/releases/download/v{{ prometheus_node_exporter_version.stdout }}/node_exporter-{{ prometheus_node_exporter_version.stdout }}.linux-amd64.tar.gz + url: https://github.com/prometheus/node_exporter/releases/download/v{{ prometheus_node_exporter_version|default(prometheus_node_exporter_latest_version.stdout) }}/node_exporter-{{ prometheus_node_exporter_version|default(prometheus_node_exporter_latest_version.stdout) }}.linux-amd64.tar.gz dest: /tmp - name: 'prometheus | node exporter | unarchive' unarchive: remote_src: yes - src: /tmp/node_exporter-{{ prometheus_node_exporter_version.stdout }}.linux-amd64.tar.gz + src: /tmp/node_exporter-{{ prometheus_node_exporter_version|default(prometheus_node_exporter_latest_version.stdout) }}.linux-amd64.tar.gz dest: /tmp - name: 'prometheus | node exporter | move to /usr/local/bin' copy: - src: /tmp/node_exporter-{{ prometheus_node_exporter_version.stdout }}.linux-amd64/node_exporter + src: /tmp/node_exporter-{{ prometheus_node_exporter_version|default(prometheus_node_exporter_latest_version.stdout) }}.linux-amd64/node_exporter dest: /usr/local/bin/prometheus-node-exporter remote_src: yes owner: root diff --git a/tasks/postgresql_exporter.yml b/tasks/postgresql_exporter.yml index 18e84cb..c1133a8 100644 --- a/tasks/postgresql_exporter.yml +++ b/tasks/postgresql_exporter.yml @@ -8,18 +8,18 @@ - name: 'prometheus | postgres exporter | download' get_url: - url: https://github.com/prometheus-community/postgres_exporter/releases/download/v{{ prometheus_postgres_exporter_version.stdout }}/postgres_exporter-{{ prometheus_postgres_exporter_version.stdout }}.linux-amd64.tar.gz + url: https://github.com/prometheus-community/postgres_exporter/releases/download/v{{ prometheus_postgres_exporter_version|default(prometheus_postgres_exporter_latest_version.stdout) }}/postgres_exporter-{{ prometheus_postgres_exporter_version|default(prometheus_postgres_exporter_latest_version.stdout) }}.linux-amd64.tar.gz dest: /tmp - name: 'prometheus | postgres exporter | unarchive' unarchive: remote_src: yes - src: /tmp/postgres_exporter-{{ prometheus_postgres_exporter_version.stdout }}.linux-amd64.tar.gz + src: /tmp/postgres_exporter-{{ prometheus_postgres_exporter_version|default(prometheus_postgres_exporter_latest_version.stdout) }}.linux-amd64.tar.gz dest: /tmp - name: 'prometheus | postgres exporter | move to /usr/local/bin' copy: - src: /tmp/postgres_exporter-{{ prometheus_postgres_exporter_version.stdout }}.linux-amd64/postgres_exporter + src: /tmp/postgres_exporter-{{ prometheus_postgres_exporter_version|default(prometheus_postgres_exporter_latest_version.stdout) }}.linux-amd64/postgres_exporter dest: /usr/local/bin/prometheus-postgres-exporter remote_src: yes owner: root