From 8aa8653e21dab2e76adf71c5afd986fc542d052b Mon Sep 17 00:00:00 2001 From: Ludovic Cartier Date: Wed, 26 May 2021 12:01:00 +0200 Subject: [PATCH] add handlers --- handlers/main.yml | 36 +++++++++++++++++++++++++ tasks/mongodb_exporter.yml | 31 ++++++++++++---------- tasks/mysqld_exporter.yml | 30 +++++++++++---------- tasks/node_exporter.yml | 30 +++++++++++---------- tasks/postgresql_exporter.yml | 49 +++++++++++++---------------------- 5 files changed, 103 insertions(+), 73 deletions(-) create mode 100644 handlers/main.yml diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..9d45f39 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,36 @@ +--- +- name: 'prometheus | server | restart container' + systemd: + name: openvpn@{{ ansible_hostname }}.service + state: started + enabled: yes + tags: ['prometheus'] + +- name: 'prometheus | node exporter | restart service' + systemd: + name: prometheus-node-exporter.service + state: restarted + enabled: yes + tags: ['prometheus'] + +- name: 'prometheus | mysqld exporter | restart service' + systemd: + name: prometheus-mysqld-exporter.service + state: restarted + enabled: yes + tags: ['prometheus'] + +- name: 'prometheus | mongodb exporter | restart service' + systemd: + name: prometheus-mongodb-exporter.service + state: restarted + enabled: yes + tags: ['prometheus'] + +- name: 'prometheus | postgres exporter | restart service' + systemd: + name: prometheus-postgres-exporter.service + state: restarted + enabled: yes + tags: ['prometheus'] + diff --git a/tasks/mongodb_exporter.yml b/tasks/mongodb_exporter.yml index 89e11c2..91306ae 100644 --- a/tasks/mongodb_exporter.yml +++ b/tasks/mongodb_exporter.yml @@ -1,4 +1,19 @@ --- +- name: 'prometheus | mongodb exporter | install unit file to systemd' + template: + src: systemd/prometheus-mongodb-exporter.service.j2 + dest: /etc/systemd/system/prometheus-mongodb-exporter.service + owner: root + group: root + mode: 0600 + +- name: 'prometheus | mongodb exporter | configure systemd to use service' + 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 @@ -18,18 +33,6 @@ owner: root group: root mode: 0755 + notify: + - 'prometheus | mysqld exporter | restart service' -- name: 'prometheus | mongodb exporter | install unit file to systemd' - template: - src: systemd/prometheus-mongodb-exporter.service.j2 - dest: /etc/systemd/system/prometheus-mongodb-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'prometheus | mongodb exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - state: started - name: prometheus-mongodb-exporter.service diff --git a/tasks/mysqld_exporter.yml b/tasks/mysqld_exporter.yml index 371bac3..47ec156 100644 --- a/tasks/mysqld_exporter.yml +++ b/tasks/mysqld_exporter.yml @@ -1,4 +1,18 @@ --- +- name: 'prometheus | mysqld exporter | install unit file to systemd' + template: + src: systemd/prometheus-mysqld-exporter.service.j2 + dest: /etc/systemd/system/prometheus-mysqld-exporter.service + owner: root + group: root + mode: 0600 + +- name: 'prometheus | mysqld exporter | configure systemd to use service' + systemd: + daemon_reload: yes + 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 @@ -33,18 +47,6 @@ when: - prometheus_mysqld_exporter_user is defined register: prometheus_mysqld_exporter_configuration + notify: + - 'prometheus | mysqld exporter | restart service' -- name: 'prometheus | mysqld exporter | install unit file to systemd' - template: - src: systemd/prometheus-mysqld-exporter.service.j2 - dest: /etc/systemd/system/prometheus-mysqld-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'prometheus | mysqld exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - state: started - name: prometheus-mysqld-exporter.service diff --git a/tasks/node_exporter.yml b/tasks/node_exporter.yml index 2e0274d..0897616 100644 --- a/tasks/node_exporter.yml +++ b/tasks/node_exporter.yml @@ -1,4 +1,18 @@ --- +- name: 'prometheus | node exporter | install unit file to systemd' + template: + src: systemd/prometheus-node-exporter.service.j2 + dest: /etc/systemd/system/prometheus-node-exporter.service + owner: root + group: root + mode: 0600 + +- name: 'prometheus | node exporter | configure systemd to use service' + systemd: + 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 @@ -18,18 +32,6 @@ 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 - dest: /etc/systemd/system/prometheus-node-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'prometheus | node exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - state: started - name: prometheus-node-exporter.service diff --git a/tasks/postgresql_exporter.yml b/tasks/postgresql_exporter.yml index 18f72d6..a7ddbc5 100644 --- a/tasks/postgresql_exporter.yml +++ b/tasks/postgresql_exporter.yml @@ -1,4 +1,20 @@ --- +- name: 'prometheus | postgres exporter | install unit file to systemd' + template: + src: systemd/prometheus-postgres-exporter.service.j2 + dest: /etc/systemd/system/prometheus-postgres-exporter.service + owner: root + group: root + mode: 0600 + + +- name: 'prometheus | postgres exporter | configure systemd to use service' + systemd: + daemon_reload: yes + enabled: yes + 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 @@ -19,22 +35,6 @@ group: root mode: 0755 -- name: 'prometheus | postgres exporter | configuration' - copy: - dest: '/var/lib/prometheus/.my.cnf' - owner: root - group: root - mode: 0644 - backup: yes - content: | - [client] - user={{ prometheus_postgres_exporter_user }} - password={{ prometheus_postgres_exporter_password }} - when: - - prometheus_postgres_exporter_user is defined - - prometheus_postgres_exporter_password is defined - register: prometheus_postgres_exporter_configuration - - name: 'prometheus | postgresql exporter | configuration' copy: dest: '/etc/default/prometheus-postgres-exporter' @@ -51,19 +51,6 @@ - prometheus_postgres_exporter_host is defined - prometheus_postgres_exporter_port is defined register: prometheu_postgres_exporter_configuration + notify: + - 'prometheus | postgres exporter | restart service' -- name: 'prometheus | postgres exporter | install unit file to systemd' - template: - src: systemd/prometheus-postgres-exporter.service.j2 - dest: /etc/systemd/system/prometheus-postgres-exporter.service - owner: root - group: root - mode: 0600 - - -- name: 'prometheus | postgres exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - state: started - name: prometheus-postgres-exporter.service