mirror of
https://github.com/prometheus-community/ansible
synced 2024-11-22 20:03:04 +00:00
102 lines
3.6 KiB
YAML
102 lines
3.6 KiB
YAML
|
---
|
||
|
- name: Assert usage of systemd as an init system
|
||
|
ansible.builtin.assert:
|
||
|
that: ansible_service_mgr == 'systemd'
|
||
|
msg: "This role only works with systemd"
|
||
|
|
||
|
- name: Install package fact dependencies
|
||
|
ansible.builtin.package:
|
||
|
name: "{{ _pkg_fact_req }}"
|
||
|
state: present
|
||
|
when: (_pkg_fact_req)
|
||
|
vars:
|
||
|
_pkg_fact_req: "{% if (ansible_pkg_mgr == 'apt') %}\
|
||
|
{{ ('python-apt' if ansible_python_version is version('3', '<') else 'python3-apt') }}
|
||
|
{% else %}\
|
||
|
{% endif %}"
|
||
|
|
||
|
- name: Gather package facts
|
||
|
ansible.builtin.package_facts:
|
||
|
when: "not 'packages' in ansible_facts"
|
||
|
|
||
|
- name: Naive assertion of proper listen address
|
||
|
ansible.builtin.assert:
|
||
|
that:
|
||
|
- "':' in mysqld_exporter_web_listen_address"
|
||
|
|
||
|
- name: Assert collectors are not both disabled and enabled at the same time
|
||
|
ansible.builtin.assert:
|
||
|
that:
|
||
|
- "item not in mysqld_exporter_enabled_collectors"
|
||
|
with_items: "{{ mysqld_exporter_disabled_collectors }}"
|
||
|
|
||
|
- name: Assert that TLS config is correct
|
||
|
when: mysqld_exporter_tls_server_config | length > 0
|
||
|
block:
|
||
|
- name: Assert that TLS key and cert path are set
|
||
|
ansible.builtin.assert:
|
||
|
that:
|
||
|
- "mysqld_exporter_tls_server_config.cert_file is defined"
|
||
|
- "mysqld_exporter_tls_server_config.key_file is defined"
|
||
|
|
||
|
- name: Check existence of TLS cert file
|
||
|
ansible.builtin.stat:
|
||
|
path: "{{ mysqld_exporter_tls_server_config.cert_file }}"
|
||
|
register: __mysqld_exporter_cert_file
|
||
|
|
||
|
- name: Check existence of TLS key file
|
||
|
ansible.builtin.stat:
|
||
|
path: "{{ mysqld_exporter_tls_server_config.key_file }}"
|
||
|
register: __mysqld_exporter_key_file
|
||
|
|
||
|
- name: Assert that TLS key and cert are present
|
||
|
ansible.builtin.assert:
|
||
|
that:
|
||
|
- "{{ __mysqld_exporter_cert_file.stat.exists }}"
|
||
|
- "{{ __mysqld_exporter_key_file.stat.exists }}"
|
||
|
|
||
|
- name: Check if mysqld_exporter is installed
|
||
|
ansible.builtin.stat:
|
||
|
path: "{{ mysqld_exporter_binary_install_dir }}/mysqld_exporter"
|
||
|
register: __mysqld_exporter_is_installed
|
||
|
check_mode: false
|
||
|
tags:
|
||
|
- mysqld_exporter_install
|
||
|
|
||
|
- name: Gather currently installed mysqld_exporter version (if any)
|
||
|
ansible.builtin.command: "{{ mysqld_exporter_binary_install_dir }}/mysqld_exporter --version"
|
||
|
changed_when: false
|
||
|
register: __mysqld_exporter_current_version_output
|
||
|
check_mode: false
|
||
|
when: __mysqld_exporter_is_installed.stat.exists
|
||
|
tags:
|
||
|
- mysqld_exporter_install
|
||
|
|
||
|
- name: Discover latest version
|
||
|
ansible.builtin.set_fact:
|
||
|
mysqld_exporter_version: "{{ (lookup('url', 'https://api.github.com/repos/prometheus/mysqld_exporter/releases/latest', split_lines=False) |
|
||
|
from_json).get('tag_name') | replace('v', '') }}"
|
||
|
run_once: true
|
||
|
until: mysqld_exporter_version is version('0.0.0', '>=')
|
||
|
retries: 10
|
||
|
when:
|
||
|
- mysqld_exporter_version == "latest"
|
||
|
- mysqld_exporter_binary_local_dir | length == 0
|
||
|
|
||
|
- name: Get mysqld_exporter binary checksum
|
||
|
when: mysqld_exporter_binary_local_dir | length == 0
|
||
|
block:
|
||
|
- name: Get checksum list from github
|
||
|
ansible.builtin.set_fact:
|
||
|
__mysqld_exporter_checksums: "{{ lookup('url', mysqld_exporter_checksums_url, wantlist=True) | list }}"
|
||
|
run_once: true
|
||
|
until: __mysqld_exporter_checksums is search('linux-' + go_arch + '.tar.gz')
|
||
|
retries: 10
|
||
|
|
||
|
- name: "Get checksum for {{ go_arch }}"
|
||
|
ansible.builtin.set_fact:
|
||
|
__mysqld_exporter_checksum: "{{ item.split(' ')[0] }}"
|
||
|
with_items: "{{ __mysqld_exporter_checksums }}"
|
||
|
when:
|
||
|
- "('linux-' + go_arch + '.tar.gz') in item"
|