From be04f2d74fc82d47f719371899adc186d7973c96 Mon Sep 17 00:00:00 2001 From: Ludovic Cartier Date: Wed, 26 May 2021 18:23:12 +0200 Subject: [PATCH] automaticaly get release version from github --- defaults/main.yml | 4 --- tasks/mongodb_exporter.yml | 49 +++++++++++++++++++--------------- tasks/mysqld_exporter.yml | 50 ++++++++++++++++++++--------------- tasks/node_exporter.yml | 50 +++++++++++++++++++---------------- tasks/postgresql_exporter.yml | 49 +++++++++++++++++++--------------- 5 files changed, 109 insertions(+), 93 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index a7df715..ed97d53 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1 @@ --- -prometheus_node_exporter_version: '1.1.2' -prometheus_mysqld_exporter_version: '0.12.1' -prometheus_postgres_exporter_version: '0.9.0' -prometheus_mongodb_exporter_version: '0.20.4' diff --git a/tasks/mongodb_exporter.yml b/tasks/mongodb_exporter.yml index 2d00cf4..5c9a6b4 100644 --- a/tasks/mongodb_exporter.yml +++ b/tasks/mongodb_exporter.yml @@ -1,4 +1,31 @@ --- +- name: 'prometheus | mongodb exporter | get latest release from GitHub' + shell: curl --silent "https://api.github.com/repos/percona/mongodb_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" + register: prometheus_mongodb_exporter_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 + dest: /tmp + +- name: 'prometheus | mongodb exporter | unarchive' + unarchive: + remote_src: yes + src: /tmp/mongodb_exporter-{{ prometheus_mongodb_exporter_version.stdout }}.linux-amd64.tar.gz + dest: /tmp + +- name: 'prometheus | mongodb exporter | move to /usr/local/bin' + copy: + src: /tmp/mongodb_exporter-{{ prometheus_mongodb_exporter_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' + - name: 'prometheus | mongodb exporter | install unit file to systemd' template: src: systemd/prometheus-mongodb-exporter.service.j2 @@ -11,29 +38,8 @@ systemd: daemon_reload: yes enabled: yes - state: started name: prometheus-mongodb-exporter.service -- name: 'prometheus | mongodb exporter | download' - get_url: - url: https://github.com/percona/mongodb_exporter/releases/download/v{{ prometheus_mongodb_exporter_version }}/mongodb_exporter-{{ prometheus_mongodb_exporter_version }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'prometheus | mongodb exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/mongodb_exporter-{{ prometheus_mongodb_exporter_version }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'prometheus | mongodb exporter | move to /usr/local/bin' - copy: - src: /tmp/mongodb_exporter-{{ prometheus_mongodb_exporter_version }}.linux-amd64/mongodb_exporter - dest: /usr/local/bin/prometheus-mongodb-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - - name: 'prometheus | mongodb exporter | configuration' template: src: prometheus-mongodb-exporter.conf.j2 @@ -43,4 +49,3 @@ mode: 0600 notify: - 'prometheus | mongodb exporter | restart service' - diff --git a/tasks/mysqld_exporter.yml b/tasks/mysqld_exporter.yml index 47ec156..0e2ddb7 100644 --- a/tasks/mysqld_exporter.yml +++ b/tasks/mysqld_exporter.yml @@ -1,4 +1,31 @@ --- +- name: 'prometheus | mysqld exporter | get latest release from GitHub' + shell: curl --silent "https://api.github.com/repos/prometheus/mysqld_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" + register: prometheus_mysqld_exporter_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 + dest: /tmp + +- name: 'prometheus | mysqld exporter | unarchive' + unarchive: + remote_src: yes + src: /tmp/mysqld_exporter-{{ prometheus_mysqld_exporter_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 + dest: /usr/local/bin/prometheus-mysqld-exporter + remote_src: yes + owner: root + group: root + mode: 0755 + notify: + - 'prometheus | mysqld exporter | restart service' + - name: 'prometheus | mysqld exporter | install unit file to systemd' template: src: systemd/prometheus-mysqld-exporter.service.j2 @@ -13,26 +40,6 @@ enabled: yes name: prometheus-mysqld-exporter.service -- name: 'prometheus | mysqld exporter | download' - get_url: - url: https://github.com/prometheus/mysqld_exporter/releases/download/v{{ prometheus_mysqld_exporter_version }}/mysqld_exporter-{{ prometheus_mysqld_exporter_version }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'prometheus | mysqld exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/mysqld_exporter-{{ prometheus_mysqld_exporter_version }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'prometheus | mysqld exporter | move to /usr/local/bin' - copy: - src: /tmp/mysqld_exporter-{{ prometheus_mysqld_exporter_version }}.linux-amd64/mysqld_exporter - dest: /usr/local/bin/prometheus-mysqld-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - - name: 'prometheus | mysqld exporter | configuration' copy: dest: '/var/lib/prometheus/.my.cnf' @@ -44,9 +51,8 @@ [client] user={{ prometheus_mysqld_exporter_user }} password={{ prometheus_mysqld_exporter_password }} - when: + when: - prometheus_mysqld_exporter_user is defined register: prometheus_mysqld_exporter_configuration notify: - 'prometheus | mysqld exporter | restart service' - diff --git a/tasks/node_exporter.yml b/tasks/node_exporter.yml index 0897616..da5678d 100644 --- a/tasks/node_exporter.yml +++ b/tasks/node_exporter.yml @@ -1,4 +1,31 @@ --- +- name: 'prometheus | node exporter | get latest release from GitHub' + shell: curl --silent "https://api.github.com/repos/prometheus/node_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" + register: prometheus_node_exporter_version + run_once: true + +- 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 + dest: /tmp + +- name: 'prometheus | node exporter | unarchive' + unarchive: + remote_src: yes + src: /tmp/node_exporter-{{ prometheus_node_exporter_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 + dest: /usr/local/bin/prometheus-node-exporter + remote_src: yes + owner: root + group: root + mode: 0755 + notify: + - 'prometheus | node exporter | restart service' + - name: 'prometheus | node exporter | install unit file to systemd' template: src: systemd/prometheus-node-exporter.service.j2 @@ -12,26 +39,3 @@ daemon_reload: yes enabled: yes name: prometheus-node-exporter.service - -- name: 'prometheus | node exporter | download' - get_url: - url: https://github.com/prometheus/node_exporter/releases/download/v{{ prometheus_node_exporter_version }}/node_exporter-{{ prometheus_node_exporter_version }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'prometheus | node exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/node_exporter-{{ prometheus_node_exporter_version }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'prometheus | node exporter | move to /usr/local/bin' - copy: - src: /tmp/node_exporter-{{ prometheus_node_exporter_version }}.linux-amd64/node_exporter - dest: /usr/local/bin/prometheus-node-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'prometheus | node exporter | restart service' - diff --git a/tasks/postgresql_exporter.yml b/tasks/postgresql_exporter.yml index 5471a32..0ad972f 100644 --- a/tasks/postgresql_exporter.yml +++ b/tasks/postgresql_exporter.yml @@ -1,4 +1,31 @@ --- +- name: 'prometheus | postgres exporter | get latest release from GitHub' + shell: curl --silent "https://api.github.com/repos/prometheus-community/postgres_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" + register: prometheus_postgres_exporter_version + run_once: true + +- 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 + dest: /tmp + +- name: 'prometheus | postgres exporter | unarchive' + unarchive: + remote_src: yes + src: /tmp/postgres_exporter-{{ prometheus_postgres_exporter_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 + dest: /usr/local/bin/prometheus-postgres-exporter + remote_src: yes + owner: root + group: root + mode: 0755 + notify: + - 'prometheus | postgres exporter | restart service' + - name: 'prometheus | postgres exporter | install unit file to systemd' template: src: systemd/prometheus-postgres-exporter.service.j2 @@ -7,7 +34,6 @@ group: root mode: 0600 - - name: 'prometheus | postgres exporter | configure systemd to use service' systemd: daemon_reload: yes @@ -15,26 +41,6 @@ state: started name: prometheus-postgres-exporter.service -- name: 'prometheus | postgres exporter | download' - get_url: - url: https://github.com/prometheus-community/postgres_exporter/releases/download/v{{ prometheus_postgres_exporter_version }}/postgres_exporter-{{ prometheus_postgres_exporter_version }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'prometheus | postgres exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/postgres_exporter-{{ prometheus_postgres_exporter_version }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'prometheus | postgres exporter | move to /usr/local/bin' - copy: - src: /tmp/postgres_exporter-{{ prometheus_postgres_exporter_version }}.linux-amd64/postgres_exporter - dest: /usr/local/bin/prometheus-postgres-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - - name: 'prometheus | postgres exporter | configuration' copy: dest: '/etc/default/prometheus-postgres-exporter' @@ -53,4 +59,3 @@ register: prometheu_postgres_exporter_configuration notify: - 'prometheus | postgres exporter | restart service' -