mirror of
https://github.com/prometheus-community/ansible
synced 2024-11-23 04:13:05 +00:00
e99b807340
Signed-off-by: gardar <gardar@users.noreply.github.com>
111 lines
3.8 KiB
YAML
111 lines
3.8 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: Get systemd version
|
|
ansible.builtin.command: systemctl --version
|
|
changed_when: false
|
|
check_mode: false
|
|
register: __systemd_version
|
|
tags:
|
|
- skip_ansible_lint
|
|
|
|
- name: Set systemd version fact
|
|
ansible.builtin.set_fact:
|
|
node_exporter_systemd_version: "{{ __systemd_version.stdout_lines[0] | regex_replace('^systemd\\s(\\d+).*$', '\\1') }}"
|
|
|
|
- name: Naive assertion of proper listen address
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "':' in node_exporter_web_listen_address"
|
|
|
|
- name: Assert collectors are not both disabled and enabled at the same time
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "item not in node_exporter_enabled_collectors"
|
|
with_items: "{{ node_exporter_disabled_collectors }}"
|
|
|
|
- block:
|
|
- name: Assert that TLS key and cert path are set
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "node_exporter_tls_server_config.cert_file is defined"
|
|
- "node_exporter_tls_server_config.key_file is defined"
|
|
|
|
- name: Check existence of TLS cert file
|
|
ansible.builtin.stat:
|
|
path: "{{ node_exporter_tls_server_config.cert_file }}"
|
|
register: __node_exporter_cert_file
|
|
|
|
- name: Check existence of TLS key file
|
|
ansible.builtin.stat:
|
|
path: "{{ node_exporter_tls_server_config.key_file }}"
|
|
register: __node_exporter_key_file
|
|
|
|
- name: Assert that TLS key and cert are present
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "{{ __node_exporter_cert_file.stat.exists }}"
|
|
- "{{ __node_exporter_key_file.stat.exists }}"
|
|
when: node_exporter_tls_server_config | length > 0
|
|
|
|
- name: Check if node_exporter is installed
|
|
ansible.builtin.stat:
|
|
path: "{{ _node_exporter_binary_install_dir }}/node_exporter"
|
|
register: __node_exporter_is_installed
|
|
check_mode: false
|
|
tags:
|
|
- node_exporter_install
|
|
|
|
- name: Gather currently installed node_exporter version (if any)
|
|
ansible.builtin.command: "{{ _node_exporter_binary_install_dir }}/node_exporter --version"
|
|
args:
|
|
warn: false
|
|
changed_when: false
|
|
register: __node_exporter_current_version_output
|
|
check_mode: false
|
|
when: __node_exporter_is_installed.stat.exists
|
|
tags:
|
|
- node_exporter_install
|
|
- skip_ansible_lint
|
|
|
|
- block:
|
|
- name: Get latest release
|
|
ansible.builtin.uri:
|
|
url: "https://api.github.com/repos/prometheus/node_exporter/releases/latest"
|
|
method: GET
|
|
return_content: true
|
|
status_code: 200
|
|
body_format: json
|
|
ansible.builtin.user: "{{ lookup('env', 'GH_USER') | default(omit) }}"
|
|
password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}"
|
|
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
|
|
register: _latest_release
|
|
until: _latest_release.status == 200
|
|
retries: 5
|
|
|
|
- name: "Set node_exporter version to {{ _latest_release.json.tag_name[1:] }}"
|
|
ansible.builtin.set_fact:
|
|
node_exporter_version: "{{ _latest_release.json.tag_name[1:] }}"
|
|
when:
|
|
- node_exporter_version == "latest"
|
|
- node_exporter_binary_local_dir | length == 0
|
|
delegate_to: localhost
|
|
run_once: true
|
|
|
|
- block:
|
|
- name: Get checksum list from github
|
|
ansible.builtin.set_fact:
|
|
_checksums: "{{ lookup('url', 'https://github.com/prometheus/node_exporter/releases/download/v' + node_exporter_version + '/sha256sums.txt', wantlist=True) | list }}"
|
|
run_once: true
|
|
|
|
- name: "Get checksum for {{ go_arch }}"
|
|
ansible.builtin.set_fact:
|
|
node_exporter_checksum: "{{ item.split(' ')[0] }}"
|
|
with_items: "{{ _checksums }}"
|
|
when:
|
|
- "('linux-' + go_arch + '.tar.gz') in item"
|
|
delegate_to: localhost
|
|
when: node_exporter_binary_local_dir | length == 0
|