exporters reorganization
This commit is contained in:
parent
f733ab6d2c
commit
78decc8f50
@ -1,130 +0,0 @@
|
||||
---
|
||||
|
||||
# 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 }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | stop old version'
|
||||
systemd:
|
||||
name: prometheus-{{ exporter }}-exporter.service
|
||||
state: stopped
|
||||
when: exporter_upgrade == "yes"
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | remove old version'
|
||||
file:
|
||||
path: /usr/local/bin/prometheus-{{ exporter }}-exporter
|
||||
state: absent
|
||||
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") and
|
||||
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") and
|
||||
prometheus_exporters_sources == "origin"
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- 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") and
|
||||
prometheus_exporters_sources == "origin"
|
||||
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 }}/
|
||||
when: >
|
||||
(not stat_result.stat.exists or exporter_upgrade == "yes") and
|
||||
prometheus_exporters_sources == "origin"
|
||||
ignore_errors: '{{ ansible_check_mode }}'
|
||||
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:
|
||||
- '{{ exporter }}-exporter-restart'
|
||||
when: >
|
||||
(not stat_result.stat.exists or exporter_upgrade == "yes") and
|
||||
prometheus_exporters_sources == "origin"
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
ignore_errors: '{{ ansible_check_mode }}'
|
||||
|
||||
- name: '{{ exporter }} exporter | cleanup temp path'
|
||||
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:
|
||||
src: systemd/prometheus-{{ exporter }}-exporter.service.j2
|
||||
dest: /etc/systemd/system/prometheus-{{ exporter }}-exporter.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0600
|
||||
notify:
|
||||
- '{{ exporter }}-exporter-restart'
|
||||
when: not stat_result.stat.exists or exporter_upgrade == "yes"
|
||||
ignore_errors: '{{ ansible_check_mode }}'
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | systemd | enable service'
|
||||
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 }}' ]
|
47
tasks/exporter/common.yml
Normal file
47
tasks/exporter/common.yml
Normal file
@ -0,0 +1,47 @@
|
||||
---
|
||||
- name: '{{ exporter }} exporter | check if exporter is already install'
|
||||
stat:
|
||||
path: /usr/local/bin/prometheus-{{ exporter }}-exporter
|
||||
register: stat_result
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name '{{ exporter }} exporter | remove old exporter version'
|
||||
include_tasks: "upgrade.yml"
|
||||
when: stat_result.stat.exists and exporter_upgrade == "yes"
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name '{{ exporter }} exporter | install from origin'
|
||||
include_tasks: "origin.yml"
|
||||
when: >
|
||||
(not stat_result.stat.exists or exporter_upgrade == "yes") and
|
||||
prometheus_exporters_sources == "origin"
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name '{{ exporter }} exporter | install from repo'
|
||||
include_tasks: "repo.yml"
|
||||
when: >
|
||||
(not stat_result.stat.exists or exporter_upgrade == "yes") and
|
||||
prometheus_exporters_sources == "repo"
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | systemd | copy unit file'
|
||||
template:
|
||||
src: systemd/prometheus-{{ exporter }}-exporter.service.j2
|
||||
dest: /etc/systemd/system/prometheus-{{ exporter }}-exporter.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0600
|
||||
notify:
|
||||
- '{{ exporter }}-exporter-restart'
|
||||
when: not stat_result.stat.exists or exporter_upgrade == "yes"
|
||||
ignore_errors: '{{ ansible_check_mode }}'
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | systemd | enable service'
|
||||
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 }}' ]
|
@ -8,7 +8,7 @@
|
||||
failed_when: result.rc != 0 and result.rc != 127
|
||||
with_items:
|
||||
- docker
|
||||
- docker-compose
|
||||
- docker-compose-plugin
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | create docker-compose directory'
|
50
tasks/exporter/origin.yml
Normal file
50
tasks/exporter/origin.yml
Normal file
@ -0,0 +1,50 @@
|
||||
---
|
||||
|
||||
# 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: '{{ exporter }} exporter | create temp path'
|
||||
file:
|
||||
state: directory
|
||||
path: /tmp/prometheus_exporter/{{ exporter }}
|
||||
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
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- 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 }}'
|
||||
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 }}/
|
||||
ignore_errors: '{{ ansible_check_mode }}'
|
||||
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:
|
||||
- '{{ exporter }}-exporter-restart'
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
ignore_errors: '{{ ansible_check_mode }}'
|
||||
|
||||
- name: '{{ exporter }} exporter | cleanup temp path'
|
||||
file:
|
||||
state: absent
|
||||
path: /tmp/prometheus_exporter/{{ exporter }}
|
11
tasks/exporter/repo.yml
Normal file
11
tasks/exporter/repo.yml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
- 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 }}'
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
@ -1,3 +1,3 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_apache_exporter']
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_blackbox_exporter']
|
||||
|
||||
- name: 'blackbox exporter | configuration'
|
@ -5,5 +5,5 @@
|
||||
- cloudflare_api_key is defined
|
||||
tags: ['prometheus_cloudflare']
|
||||
|
||||
- include_tasks: _docker.yml
|
||||
- include_tasks: ../docker.yml
|
||||
tags: ['prometheus_cloudflare']
|
@ -1,3 +1,3 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_memcached_exporter']
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_mongodb_exporter']
|
||||
|
||||
- name: 'mongodb exporter < v0.2 | move to /usr/local/bin'
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_mysqld_exporter']
|
||||
|
||||
- name: 'mysqld exporter | configuration'
|
@ -1,3 +1,3 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_nginx_exporter']
|
@ -1,3 +1,3 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_node_exporter']
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_opcache_exporter']
|
||||
|
||||
- name: 'opcache exporter | configuration'
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_phpfpm_exporter']
|
||||
|
||||
- name: 'phpfpm exporter | install startup script'
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_postgres_exporter']
|
||||
|
||||
- name: 'postgres exporter | configuration'
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_redis_exporter']
|
||||
|
||||
- name: 'redis exporter | configuration'
|
@ -1,3 +1,3 @@
|
||||
---
|
||||
- include_tasks: _common.yml
|
||||
- include_tasks: ../common.yml
|
||||
tags: ['prometheus_varnish_exporter']
|
12
tasks/exporter/upgrade.yml
Normal file
12
tasks/exporter/upgrade.yml
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
- name: '{{ exporter }} exporter | stop old version'
|
||||
systemd:
|
||||
name: prometheus-{{ exporter }}-exporter.service
|
||||
state: stopped
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
||||
|
||||
- name: '{{ exporter }} exporter | remove old version'
|
||||
file:
|
||||
path: /usr/local/bin/prometheus-{{ exporter }}-exporter
|
||||
state: absent
|
||||
tags: [ 'prometheus_{{ exporter }}' ]
|
@ -24,7 +24,7 @@
|
||||
- name: 'exporters install'
|
||||
vars:
|
||||
exporter: "{{ item }}"
|
||||
include_tasks: "exporter/{{ item }}.yml"
|
||||
include_tasks: "exporter/services/{{ item }}.yml"
|
||||
tags:
|
||||
- prometheus_node_exporter
|
||||
- prometheus_mysqld_exporter
|
||||
|
Loading…
x
Reference in New Issue
Block a user