From ad51f0b0881f777b3623346953921913563b6da4 Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Tue, 6 Aug 2024 15:57:53 +0200 Subject: [PATCH 01/26] feat: include influxdb exporter role Include the [Influxdb exporter](https://github.com/prometheus/influxdb_exporter) role. Signed-off-by: dobbi84 --- roles/influxdb_exporter/README.md | 54 ++++++++++++++ roles/influxdb_exporter/defaults/main.yml | 23 ++++++ roles/influxdb_exporter/handlers/main.yml | 10 +++ .../influxdb_exporter/meta/argument_specs.yml | 72 ++++++++++++++++++ roles/influxdb_exporter/meta/main.yml | 25 +++++++ .../molecule/alternative/molecule.yml | 12 +++ .../molecule/alternative/prepare.yml | 35 +++++++++ .../alternative/tests/test_alternative.py | 39 ++++++++++ .../molecule/default/molecule.yml | 6 ++ .../molecule/default/tests/test_default.py | 73 +++++++++++++++++++ .../molecule/latest/molecule.yml | 6 ++ .../molecule/latest/tests/test_latest.py | 37 ++++++++++ roles/influxdb_exporter/tasks/configure.yml | 27 +++++++ roles/influxdb_exporter/tasks/install.yml | 69 ++++++++++++++++++ roles/influxdb_exporter/tasks/main.yml | 59 +++++++++++++++ roles/influxdb_exporter/tasks/preflight.yml | 54 ++++++++++++++ roles/influxdb_exporter/tasks/selinux.yml | 12 +++ .../templates/influxdb_exporter.service.j2 | 31 ++++++++ roles/influxdb_exporter/test-requirements.txt | 1 + roles/influxdb_exporter/vars/main.yml | 3 + 20 files changed, 648 insertions(+) create mode 100644 roles/influxdb_exporter/README.md create mode 100644 roles/influxdb_exporter/defaults/main.yml create mode 100644 roles/influxdb_exporter/handlers/main.yml create mode 100644 roles/influxdb_exporter/meta/argument_specs.yml create mode 100644 roles/influxdb_exporter/meta/main.yml create mode 100644 roles/influxdb_exporter/molecule/alternative/molecule.yml create mode 100644 roles/influxdb_exporter/molecule/alternative/prepare.yml create mode 100644 roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py create mode 100644 roles/influxdb_exporter/molecule/default/molecule.yml create mode 100644 roles/influxdb_exporter/molecule/default/tests/test_default.py create mode 100644 roles/influxdb_exporter/molecule/latest/molecule.yml create mode 100644 roles/influxdb_exporter/molecule/latest/tests/test_latest.py create mode 100644 roles/influxdb_exporter/tasks/configure.yml create mode 100644 roles/influxdb_exporter/tasks/install.yml create mode 100644 roles/influxdb_exporter/tasks/main.yml create mode 100644 roles/influxdb_exporter/tasks/preflight.yml create mode 100644 roles/influxdb_exporter/tasks/selinux.yml create mode 100644 roles/influxdb_exporter/templates/influxdb_exporter.service.j2 create mode 100644 roles/influxdb_exporter/test-requirements.txt create mode 100644 roles/influxdb_exporter/vars/main.yml diff --git a/roles/influxdb_exporter/README.md b/roles/influxdb_exporter/README.md new file mode 100644 index 000000000..887014929 --- /dev/null +++ b/roles/influxdb_exporter/README.md @@ -0,0 +1,54 @@ +# Ansible Role: influxdb exporter + +## Description + +Deploy prometheus [influxdb exporter](https://github.com/prometheus/influxdb_exporter) using ansible. + +## Requirements + +- Ansible >= 2.9 (It might work on previous versions, but we cannot guarantee it) +- gnu-tar on Mac deployer host (`brew install gnu-tar`) + +## Role Variables + +All variables which can be overridden are stored in [defaults/main.yml](defaults/main.yml) file as well as in [meta/argument_specs.yml](meta/argument_specs.yml). +Please refer to the [collection docs](https://prometheus-community.github.io/ansible/branch/main/influxdb_exporter_role.html) for description and default values of the variables. + +## Example + +### Playbook + +Use it in a playbook as follows: + +```yaml +- hosts: all + roles: + - prometheus.prometheus.influxdb_exporter +``` + +### Demo site + +We provide an example site that demonstrates a full monitoring solution based on prometheus and grafana. +The repository with code and links to running instances is [available on github](https://github.com/prometheus/demo-site) and the site is hosted on [DigitalOcean](https://digitalocean.com). + +## Local Testing + +The preferred way of locally testing the role is to use Docker and [molecule](https://github.com/ansible-community/molecule) (v3.x). +You will have to install Docker on your system. See "Get started" for a Docker package suitable for your system. Running your tests is as simple as executing `molecule test`. + +## Continuous Integration + +Combining molecule and circle CI allows us to test how new PRs will behave when used with multiple ansible versions and multiple operating systems. +This also allows use to create test scenarios for different role configurations. As a result we have quite a large test matrix which can take more time than local testing, so please be patient. + +## Contributing + +See [contributor guideline](CONTRIBUTING.md). + +## Troubleshooting + +See [troubleshooting](TROUBLESHOOTING.md). + +## License + +This project is licensed under MIT License. See [LICENSE](/LICENSE) for more details. diff --git a/roles/influxdb_exporter/defaults/main.yml b/roles/influxdb_exporter/defaults/main.yml new file mode 100644 index 000000000..20441ca7a --- /dev/null +++ b/roles/influxdb_exporter/defaults/main.yml @@ -0,0 +1,23 @@ +--- +influxdb_exporter_version: "0.11.5" +influxdb_exporter_binary_local_dir: "" +influxdb_exporter_binary_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/\ + influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" +influxdb_exporter_checksums_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/sha256sums.txt" +influxdb_exporter_skip_install: false + +influxdb_exporter_web_listen_address: "0.0.0.0:9122" +influxdb_exporter_udp_bind_address: "{{ influxdb_exporter_web_listen_address }}" +influxdb_exporter_web_telemetry_path: "/metrics" +influxdb_exporter_exporter_web_telemetry_path: "/metrics/exporter" +influxdb_exporter_influxdb_sample_expiry: "5m" +influxdb_exporter_log_level: "info" +influxdb_exporter_log_format: "logfmt" +influxdb_exporter_export_timestamps: true + +influxdb_exporter_binary_install_dir: "/usr/local/bin" +influxdb_exporter_system_group: "influxdb-exp" +influxdb_exporter_system_user: "{{ influxdb_exporter_system_group }}" + +# Local path to stash the archive and its extraction +influxdb_exporter_archive_path: /tmp diff --git a/roles/influxdb_exporter/handlers/main.yml b/roles/influxdb_exporter/handlers/main.yml new file mode 100644 index 000000000..ccdfd1c12 --- /dev/null +++ b/roles/influxdb_exporter/handlers/main.yml @@ -0,0 +1,10 @@ +--- +- name: Restart influxdb_exporter + listen: "restart influxdb_exporter" + become: true + ansible.builtin.systemd: + daemon_reload: true + name: influxdb_exporter + state: restarted + when: + - not ansible_check_mode diff --git a/roles/influxdb_exporter/meta/argument_specs.yml b/roles/influxdb_exporter/meta/argument_specs.yml new file mode 100644 index 000000000..9f980e7b5 --- /dev/null +++ b/roles/influxdb_exporter/meta/argument_specs.yml @@ -0,0 +1,72 @@ +--- +# yamllint disable rule:line-length +argument_specs: + main: + short_description: "Prometheus Influxdb Exporter" + description: + - "Deploy prometheus L(influxdb exporter,https://github.com/prometheus/influxdb_exporter) using ansible" + author: + - "Prometheus Community" + options: + influxdb_exporter_version: + description: "influxdb exporter package version. Also accepts latest as parameter." + default: "0.11.5" + influxdb_exporter_skip_install: + description: "influxdb exporter installation tasks gets skipped when set to true." + type: bool + default: false + influxdb_exporter_binary_local_dir: + description: + - "Enables the use of local packages instead of those distributed on github." + - "The parameter may be set to a directory where the C(influxdb_exporter) binary is stored on the host where ansible is run." + - "This overrides the I(influxdb_exporter_version) parameter" + influxdb_exporter_binary_url: + description: "URL of the influxdb exporter binaries .tar.gz file" + default: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" + influxdb_exporter_checksums_url: + description: "URL of the influxdb exporter checksums file" + default: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/sha256sums.txt" + influxdb_exporter_web_listen_address: + description: "Address on which influxdb exporter will listen" + default: "0.0.0.0:9122" + influxdb_exporter_web_telemetry_path: + description: "Path under which to expose metrics" + default: "/metrics" + influxdb_exporter_influxdb_sample_expiry: + description: "How long a sample is valid for" + default: "5m" + influxdb_exporter_udp_bind_address: + description: "Address on which to listen for udp packets" + default: "0.0.0.0:9122" + influxdb_exporter_exporter_web_telemetry_path: + description: "Path under which to expose metrics" + default: "/metrics" + influxdb_exporter_log_level: + default: "info" + description: "Only log messages with the given severity or above" + choices: ["debug", "info", "warn", "error"] + influxdb_exporter_log_format: + default: "logfmt" + description: "Output format of log messages" + choices: ["logfmt", "json"] + influxdb_exporter_export_timestamps: + default: true + description: "Export timestamps of points" + influxdb_exporter_binary_install_dir: + description: + - "I(Advanced)" + - "Directory to install influxdb_exporter binary" + default: "/usr/local/bin" + influxdb_exporter_system_group: + description: + - "I(Advanced)" + - "System group for influxdb exporter" + default: "influxdb-exp" + influxdb_exporter_system_user: + description: + - "I(Advanced)" + - "influxdb exporter user" + default: "influxdb-exp" + influxdb_exporter_archive_path: + description: 'Local path to stash the archive and its extraction' + default: "/tmp" diff --git a/roles/influxdb_exporter/meta/main.yml b/roles/influxdb_exporter/meta/main.yml new file mode 100644 index 000000000..32f4d0969 --- /dev/null +++ b/roles/influxdb_exporter/meta/main.yml @@ -0,0 +1,25 @@ +--- +galaxy_info: + author: "Prometheus Community" + description: "Prometheus Influxdb Exporter" + license: "Apache" + min_ansible_version: "2.9" + platforms: + - name: "Ubuntu" + versions: + - "focal" + - "jammy" + - name: "Debian" + versions: + - "bullseye" + - "buster" + - name: "EL" + versions: + - "8" + - "9" + galaxy_tags: + - "monitoring" + - "prometheus" + - "exporter" + - "metrics" + - "system" diff --git a/roles/influxdb_exporter/molecule/alternative/molecule.yml b/roles/influxdb_exporter/molecule/alternative/molecule.yml new file mode 100644 index 000000000..c2cdb59bf --- /dev/null +++ b/roles/influxdb_exporter/molecule/alternative/molecule.yml @@ -0,0 +1,12 @@ +--- +provisioner: + inventory: + group_vars: + all: + influxdb_exporter_binary_local_dir: "/tmp/influxdb_exporter-linux-amd64" + influxdb_exporter_web_listen_address: + - '127.0.0.1:8080' + - '127.0.1.1:8080' + + go_arch: amd64 + influxdb_exporter_version: 0.11.2 diff --git a/roles/influxdb_exporter/molecule/alternative/prepare.yml b/roles/influxdb_exporter/molecule/alternative/prepare.yml new file mode 100644 index 000000000..772b9f6c7 --- /dev/null +++ b/roles/influxdb_exporter/molecule/alternative/prepare.yml @@ -0,0 +1,35 @@ +--- +- name: Run local preparation + hosts: localhost + gather_facts: false + tasks: + - name: Download influxdb_exporter binary to local folder + become: false + ansible.builtin.get_url: + url: "https://github.com/prometheus/influxdb_exporter/releases/download/v{{\ + \ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{\ + \ go_arch }}.tar.gz" + dest: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" + mode: 0644 + register: _download_binary + until: _download_binary is succeeded + retries: 5 + delay: 2 + check_mode: false + + - name: Unpack influxdb_exporter binary + become: false + ansible.builtin.unarchive: + src: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" + dest: "/tmp" + creates: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch\ + \ }}/influxdb_exporter" + check_mode: false + + - name: Link to influxdb_exporter binaries directory + become: false + ansible.builtin.file: + src: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-amd64" + dest: "/tmp/influxdb_exporter-linux-amd64" + state: link + check_mode: false diff --git a/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py b/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py new file mode 100644 index 000000000..1077badc2 --- /dev/null +++ b/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py @@ -0,0 +1,39 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import os +import testinfra.utils.ansible_runner +import pytest + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_directories(host): + dirs = [ + "/var/lib/influxdb_exporter" + ] + for dir in dirs: + d = host.file(dir) + assert not d.exists + + +def test_service(host): + s = host.service("influxdb_exporter") + try: + assert s.is_running + except AssertionError: + # Capture service logs + journal_output = host.run('journalctl -u influxdb_exporter --since "1 hour ago"') + print("\n==== journalctl -u influxdb_exporter Output ====\n") + print(journal_output) + print("\n============================================\n") + raise # Re-raise the original assertion error + + +@pytest.mark.parametrize("sockets", [ + "tcp://127.0.0.1:8080", + "tcp://127.0.1.1:8080", +]) +def test_socket(host, sockets): + assert host.socket(sockets).is_listening diff --git a/roles/influxdb_exporter/molecule/default/molecule.yml b/roles/influxdb_exporter/molecule/default/molecule.yml new file mode 100644 index 000000000..3da70d0c9 --- /dev/null +++ b/roles/influxdb_exporter/molecule/default/molecule.yml @@ -0,0 +1,6 @@ +--- +provisioner: + inventory: + group_vars: + all: + influxdb_exporter_web_listen_address: "127.0.0.1:9122" diff --git a/roles/influxdb_exporter/molecule/default/tests/test_default.py b/roles/influxdb_exporter/molecule/default/tests/test_default.py new file mode 100644 index 000000000..18022851c --- /dev/null +++ b/roles/influxdb_exporter/molecule/default/tests/test_default.py @@ -0,0 +1,73 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import os +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_directories(host): + dirs = [ + "/var/lib/influxdb_exporter" + ] + for dir in dirs: + d = host.file(dir) + assert d.is_directory + assert d.exists + + +def test_files(host): + files = [ + "/etc/systemd/system/influxdb_exporter.service", + "/usr/local/bin/influxdb_exporter" + ] + for file in files: + f = host.file(file) + assert f.exists + assert f.is_file + + +def test_permissions_didnt_change(host): + dirs = [ + "/etc", + "/root", + "/usr", + "/var" + ] + for file in dirs: + f = host.file(file) + assert f.exists + assert f.is_directory + assert f.user == "root" + assert f.group == "root" + + +def test_user(host): + assert host.group("influxdb-exp").exists + assert "influxdb-exp" in host.user("influxdb-exp").groups + assert host.user("influxdb-exp").shell == "/usr/sbin/nologin" + assert host.user("influxdb-exp").home == "/" + + +def test_service(host): + s = host.service("influxdb_exporter") + try: + assert s.is_running + except AssertionError: + # Capture service logs + journal_output = host.run('journalctl -u influxdb_exporter --since "1 hour ago"') + print("\n==== journalctl -u influxdb_exporter Output ====\n") + print(journal_output) + print("\n============================================\n") + raise # Re-raise the original assertion error + + +def test_socket(host): + sockets = [ + "tcp://127.0.0.1:9122" + ] + for socket in sockets: + s = host.socket(socket) + assert s.is_listening diff --git a/roles/influxdb_exporter/molecule/latest/molecule.yml b/roles/influxdb_exporter/molecule/latest/molecule.yml new file mode 100644 index 000000000..228dfa3ad --- /dev/null +++ b/roles/influxdb_exporter/molecule/latest/molecule.yml @@ -0,0 +1,6 @@ +--- +provisioner: + inventory: + group_vars: + all: + influxdb_exporter_version: latest diff --git a/roles/influxdb_exporter/molecule/latest/tests/test_latest.py b/roles/influxdb_exporter/molecule/latest/tests/test_latest.py new file mode 100644 index 000000000..551edab40 --- /dev/null +++ b/roles/influxdb_exporter/molecule/latest/tests/test_latest.py @@ -0,0 +1,37 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import os +import testinfra.utils.ansible_runner +import pytest + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +@pytest.mark.parametrize("files", [ + "/etc/systemd/system/influxdb_exporter.service", + "/usr/local/bin/influxdb_exporter" +]) +def test_files(host, files): + f = host.file(files) + assert f.exists + assert f.is_file + + +def test_service(host): + s = host.service("influxdb_exporter") + try: + assert s.is_running + except AssertionError: + # Capture service logs + journal_output = host.run('journalctl -u influxdb_exporter --since "1 hour ago"') + print("\n==== journalctl -u influxdb_exporter Output ====\n") + print(journal_output) + print("\n============================================\n") + raise # Re-raise the original assertion error + + +def test_socket(host): + s = host.socket("tcp://0.0.0.0:9122") + assert s.is_listening diff --git a/roles/influxdb_exporter/tasks/configure.yml b/roles/influxdb_exporter/tasks/configure.yml new file mode 100644 index 000000000..2ca839b4d --- /dev/null +++ b/roles/influxdb_exporter/tasks/configure.yml @@ -0,0 +1,27 @@ +--- +- name: Copy the influxdb_exporter systemd service file + ansible.builtin.template: + src: influxdb_exporter.service.j2 + dest: /etc/systemd/system/influxdb_exporter.service + owner: root + group: root + mode: 0644 + notify: restart influxdb_exporter + +- name: Create influxdb_exporter config directory + ansible.builtin.file: + path: "/etc/influxdb_exporter" + state: directory + owner: root + group: root + mode: u+rwX,g+rwX,o=rX + +- name: Allow influxdb_exporter port in SELinux on RedHat OS family + community.general.seport: + ports: "{{ influxdb_exporter_web_listen_address.split(':')[-1] }}" + proto: tcp + setype: http_port_t + state: present + when: + - ansible_version.full is version_compare('2.4', '>=') + - ansible_selinux.status == "enabled" diff --git a/roles/influxdb_exporter/tasks/install.yml b/roles/influxdb_exporter/tasks/install.yml new file mode 100644 index 000000000..ad84ab474 --- /dev/null +++ b/roles/influxdb_exporter/tasks/install.yml @@ -0,0 +1,69 @@ +--- +- name: Create the influxdb_exporter group + ansible.builtin.group: + name: "{{ influxdb_exporter_system_group }}" + state: present + system: true + when: influxdb_exporter_system_group != "root" + +- name: Create the influxdb_exporter user + ansible.builtin.user: + name: "{{ influxdb_exporter_system_user }}" + groups: "{{ influxdb_exporter_system_group }}" + append: true + shell: /usr/sbin/nologin + system: true + create_home: false + home: / + when: influxdb_exporter_system_user != "root" + +- name: Get binary + when: + - influxdb_exporter_binary_local_dir | length == 0 + - not influxdb_exporter_skip_install + block: + + - name: Download influxdb_exporter binary to local folder + become: false + ansible.builtin.get_url: + url: "{{ influxdb_exporter_binary_url }}" + dest: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" + checksum: "sha256:{{ __influxdb_exporter_checksum }}" + mode: '0644' + register: _download_binary + until: _download_binary is succeeded + retries: 5 + delay: 2 + delegate_to: localhost + check_mode: false + + - name: Unpack influxdb_exporter binary + become: false + ansible.builtin.unarchive: + src: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" + dest: "{{ influxdb_exporter_archive_path }}" + creates: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}/influxdb_exporter" + delegate_to: localhost + check_mode: false + + - name: Propagate influxdb_exporter binaries + ansible.builtin.copy: + src: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}/influxdb_exporter" + dest: "{{ influxdb_exporter_binary_install_dir }}/influxdb_exporter" + mode: 0755 + owner: root + group: root + notify: restart influxdb_exporter + when: not ansible_check_mode + +- name: Propagate locally distributed influxdb_exporter binary + ansible.builtin.copy: + src: "{{ influxdb_exporter_binary_local_dir }}/influxdb_exporter" + dest: "{{ influxdb_exporter_binary_install_dir }}/influxdb_exporter" + mode: 0755 + owner: root + group: root + when: + - influxdb_exporter_binary_local_dir | length > 0 + - not influxdb_exporter_skip_install + notify: restart influxdb_exporter diff --git a/roles/influxdb_exporter/tasks/main.yml b/roles/influxdb_exporter/tasks/main.yml new file mode 100644 index 000000000..d58543e08 --- /dev/null +++ b/roles/influxdb_exporter/tasks/main.yml @@ -0,0 +1,59 @@ +--- +- name: Preflight + ansible.builtin.include_tasks: + file: preflight.yml + apply: + tags: + - influxdb_exporter_install + - influxdb_exporter_configure + - influxdb_exporter_run + tags: + - influxdb_exporter_install + - influxdb_exporter_configure + - influxdb_exporter_run + +- name: Install + ansible.builtin.include_tasks: + file: install.yml + apply: + become: true + tags: + - influxdb_exporter_install + when: + ( not __influxdb_exporter_is_installed.stat.exists ) or + ( influxdb_exporter_binary_local_dir | length > 0 ) + tags: + - influxdb_exporter_install + +- name: SELinux + ansible.builtin.include_tasks: + file: selinux.yml + apply: + become: true + tags: + - influxdb_exporter_configure + when: ansible_selinux.status == "enabled" + tags: + - influxdb_exporter_configure + +- name: Configure + ansible.builtin.include_tasks: + file: configure.yml + apply: + become: true + tags: + - influxdb_exporter_configure + tags: + - influxdb_exporter_configure + +- name: Ensure Influxdb Exporter is enabled on boot + become: true + ansible.builtin.systemd: + daemon_reload: true + name: influxdb_exporter + enabled: true + state: started + when: + - not ansible_check_mode + tags: + - influxdb_exporter_run diff --git a/roles/influxdb_exporter/tasks/preflight.yml b/roles/influxdb_exporter/tasks/preflight.yml new file mode 100644 index 000000000..4c27fb433 --- /dev/null +++ b/roles/influxdb_exporter/tasks/preflight.yml @@ -0,0 +1,54 @@ +--- +- 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: Naive assertion of proper listen address + ansible.builtin.assert: + that: + - >- + [influxdb_exporter_web_listen_address] | + flatten | + reject('match', '.+:\\d+$') | + list | + length == 0 + +- name: Check if influxdb_exporter is installed + ansible.builtin.stat: + path: "{{ influxdb_exporter_binary_install_dir }}/influxdb_exporter" + register: __influxdb_exporter_is_installed + check_mode: false + tags: + - influxdb_exporter_install + +- name: Discover latest version + ansible.builtin.set_fact: + influxdb_exporter_version: "{{ (lookup('url', 'https://api.github.com/repos/{{ _influxdb_exporter_repo }}/releases/latest', headers=_influxdb_exporter_github_api_headers, + split_lines=False) | from_json).get('tag_name') | replace('v', '') }}" + run_once: true + until: influxdb_exporter_version is version('0.0.0', '>=') + retries: 10 + when: + - influxdb_exporter_version == "latest" + - influxdb_exporter_binary_local_dir | length == 0 + - not influxdb_exporter_skip_install + +- name: Get influxdb_exporter binary checksum + when: + - influxdb_exporter_binary_local_dir | length == 0 + - not influxdb_exporter_skip_install + block: + - name: Get checksum list from github + ansible.builtin.set_fact: + __influxdb_exporter_checksums: "{{ lookup('url', influxdb_exporter_checksums_url, headers=_influxdb_exporter_github_api_headers, wantlist=True) | list }}" + run_once: true + until: __influxdb_exporter_checksums is search('linux-' + go_arch + '.tar.gz') + retries: 10 + + - name: "Get checksum for {{ go_arch }}" + ansible.builtin.set_fact: + __influxdb_exporter_checksum: "{{ item.split(' ')[0] }}" + with_items: "{{ __influxdb_exporter_checksums }}" + when: + - "('linux-' + go_arch + '.tar.gz') in item" diff --git a/roles/influxdb_exporter/tasks/selinux.yml b/roles/influxdb_exporter/tasks/selinux.yml new file mode 100644 index 000000000..b8eff9b45 --- /dev/null +++ b/roles/influxdb_exporter/tasks/selinux.yml @@ -0,0 +1,12 @@ +--- +- name: Install selinux python packages [RedHat] + ansible.builtin.package: + name: "{{ ['libselinux-python', 'policycoreutils-python'] + if ansible_python_version is version('3', '<') else + ['python3-libselinux', 'python3-policycoreutils'] }}" + state: present + register: _install_selinux_packages + until: _install_selinux_packages is success + retries: 5 + delay: 2 + when: ansible_os_family | lower == "redhat" diff --git a/roles/influxdb_exporter/templates/influxdb_exporter.service.j2 b/roles/influxdb_exporter/templates/influxdb_exporter.service.j2 new file mode 100644 index 000000000..ec47a40e1 --- /dev/null +++ b/roles/influxdb_exporter/templates/influxdb_exporter.service.j2 @@ -0,0 +1,31 @@ +{{ ansible_managed | comment }} + +[Unit] +Description=Influxdb to Prometheus Exporter Service +After=network-online.target + +[Service] +Type=simple +User={{ influxdb_exporter_system_user }} +Group={{ influxdb_exporter_system_group }} +ExecStart={{ influxdb_exporter_binary_install_dir }}/influxdb_exporter \ + '--web.listen-address={{ influxdb_exporter_web_listen_address }}' \ + '--udp.bind-address={{ influxdb_exporter_udp_bind_address }}' \ + '--web.telemetry-path={{ influxdb_exporter_web_telemetry_path }}' \ + '--web.exporter-telemetry-path={{ influxdb_exporter_exporter_web_telemetry_path }}' \ + '--influxdb.sample-expiry={{ influxdb_exporter_influxdb_sample_expiry }}' \ + '--log.level={{ influxdb_exporter_log_level }}' \ + '--log.format={{ influxdb_exporter_log_format }}' \ +{% if influxdb_exporter_export_timestamps %} + '--timestamps' +{% else %} + '--no-timestamps' +{% endif %} + +SyslogIdentifier=influxdb_exporter +Restart=always +RestartSec=1 +StartLimitInterval=0 + +[Install] +WantedBy=multi-user.target diff --git a/roles/influxdb_exporter/test-requirements.txt b/roles/influxdb_exporter/test-requirements.txt new file mode 100644 index 000000000..7f0b6e759 --- /dev/null +++ b/roles/influxdb_exporter/test-requirements.txt @@ -0,0 +1 @@ +bcrypt diff --git a/roles/influxdb_exporter/vars/main.yml b/roles/influxdb_exporter/vars/main.yml new file mode 100644 index 000000000..934f8ff0a --- /dev/null +++ b/roles/influxdb_exporter/vars/main.yml @@ -0,0 +1,3 @@ +--- +_influxdb_exporter_repo: "prometheus/influxdb_exporter" +_influxdb_exporter_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}" From dd0dbaadd6f94a53b4ef4f059862419c909392b6 Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Wed, 25 Sep 2024 08:45:06 +0200 Subject: [PATCH 02/26] chore: include boiler plate for integration testing Signed-off-by: dobbi84 --- .../targets/molecule-influxdb_exporter-alternative/runme.sh | 4 ++++ .../targets/molecule-influxdb_exporter-default/runme.sh | 4 ++++ .../targets/molecule-influxdb_exporter-latest/runme.sh | 4 ++++ 3 files changed, 12 insertions(+) create mode 100755 tests/integration/targets/molecule-influxdb_exporter-alternative/runme.sh create mode 100755 tests/integration/targets/molecule-influxdb_exporter-default/runme.sh create mode 100755 tests/integration/targets/molecule-influxdb_exporter-latest/runme.sh diff --git a/tests/integration/targets/molecule-influxdb_exporter-alternative/runme.sh b/tests/integration/targets/molecule-influxdb_exporter-alternative/runme.sh new file mode 100755 index 000000000..d094c3e1b --- /dev/null +++ b/tests/integration/targets/molecule-influxdb_exporter-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-influxdb_exporter-default/runme.sh b/tests/integration/targets/molecule-influxdb_exporter-default/runme.sh new file mode 100755 index 000000000..d094c3e1b --- /dev/null +++ b/tests/integration/targets/molecule-influxdb_exporter-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-influxdb_exporter-latest/runme.sh b/tests/integration/targets/molecule-influxdb_exporter-latest/runme.sh new file mode 100755 index 000000000..d094c3e1b --- /dev/null +++ b/tests/integration/targets/molecule-influxdb_exporter-latest/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" From 745154f8d55784373db5c31ca4981953889af307 Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Wed, 25 Sep 2024 09:11:29 +0200 Subject: [PATCH 03/26] chore: include vars go_arch and go_arch_map needed for getting the exporter from GH Signed-off-by: dobbi84 --- roles/influxdb_exporter/vars/main.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/roles/influxdb_exporter/vars/main.yml b/roles/influxdb_exporter/vars/main.yml index 934f8ff0a..4c7f04617 100644 --- a/roles/influxdb_exporter/vars/main.yml +++ b/roles/influxdb_exporter/vars/main.yml @@ -1,3 +1,11 @@ --- +go_arch_map: + i386: '386' + x86_64: 'amd64' + aarch64: 'arm64' + armv7l: 'armv7' + armv6l: 'armv6' + +go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}" _influxdb_exporter_repo: "prometheus/influxdb_exporter" _influxdb_exporter_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}" From e22cd9f9f18c0d285bc5b50c950e3479570dabc0 Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Wed, 25 Sep 2024 09:33:10 +0200 Subject: [PATCH 04/26] chore: remove molecule directory check for dir not created Signed-off-by: dobbi84 --- .../molecule/alternative/tests/test_alternative.py | 9 --------- .../molecule/default/tests/test_default.py | 10 ---------- roles/influxdb_exporter/tasks/configure.yml | 8 -------- 3 files changed, 27 deletions(-) diff --git a/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py b/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py index 1077badc2..058d8b619 100644 --- a/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py @@ -9,15 +9,6 @@ os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') -def test_directories(host): - dirs = [ - "/var/lib/influxdb_exporter" - ] - for dir in dirs: - d = host.file(dir) - assert not d.exists - - def test_service(host): s = host.service("influxdb_exporter") try: diff --git a/roles/influxdb_exporter/molecule/default/tests/test_default.py b/roles/influxdb_exporter/molecule/default/tests/test_default.py index 18022851c..822979c6c 100644 --- a/roles/influxdb_exporter/molecule/default/tests/test_default.py +++ b/roles/influxdb_exporter/molecule/default/tests/test_default.py @@ -8,16 +8,6 @@ os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') -def test_directories(host): - dirs = [ - "/var/lib/influxdb_exporter" - ] - for dir in dirs: - d = host.file(dir) - assert d.is_directory - assert d.exists - - def test_files(host): files = [ "/etc/systemd/system/influxdb_exporter.service", diff --git a/roles/influxdb_exporter/tasks/configure.yml b/roles/influxdb_exporter/tasks/configure.yml index 2ca839b4d..a6eb22674 100644 --- a/roles/influxdb_exporter/tasks/configure.yml +++ b/roles/influxdb_exporter/tasks/configure.yml @@ -8,14 +8,6 @@ mode: 0644 notify: restart influxdb_exporter -- name: Create influxdb_exporter config directory - ansible.builtin.file: - path: "/etc/influxdb_exporter" - state: directory - owner: root - group: root - mode: u+rwX,g+rwX,o=rX - - name: Allow influxdb_exporter port in SELinux on RedHat OS family community.general.seport: ports: "{{ influxdb_exporter_web_listen_address.split(':')[-1] }}" From 10d70f06a4246aaf4b2b16d8346f985de339a792 Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Wed, 25 Sep 2024 10:21:07 +0200 Subject: [PATCH 05/26] chore: fix alternative listen address in integration tests Signed-off-by: dobbi84 --- roles/influxdb_exporter/molecule/alternative/molecule.yml | 4 +--- .../molecule/alternative/tests/test_alternative.py | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/roles/influxdb_exporter/molecule/alternative/molecule.yml b/roles/influxdb_exporter/molecule/alternative/molecule.yml index c2cdb59bf..31fd870e5 100644 --- a/roles/influxdb_exporter/molecule/alternative/molecule.yml +++ b/roles/influxdb_exporter/molecule/alternative/molecule.yml @@ -4,9 +4,7 @@ provisioner: group_vars: all: influxdb_exporter_binary_local_dir: "/tmp/influxdb_exporter-linux-amd64" - influxdb_exporter_web_listen_address: - - '127.0.0.1:8080' - - '127.0.1.1:8080' + influxdb_exporter_web_listen_address: '127.0.0.1:8080' go_arch: amd64 influxdb_exporter_version: 0.11.2 diff --git a/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py b/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py index 058d8b619..33196f0b7 100644 --- a/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py @@ -24,7 +24,6 @@ def test_service(host): @pytest.mark.parametrize("sockets", [ "tcp://127.0.0.1:8080", - "tcp://127.0.1.1:8080", ]) def test_socket(host, sockets): assert host.socket(sockets).is_listening From 02aefecad20fc2319585566d0f092495bd5a0b6e Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Thu, 3 Oct 2024 12:15:55 +0200 Subject: [PATCH 06/26] chore: align molecule tests to use get_target_hosts() Signed-off-by: dobbi84 --- roles/influxdb_exporter/meta/main.yml | 6 +++++- .../molecule/alternative/tests/test_alternative.py | 6 ++---- .../molecule/default/tests/test_default.py | 6 ++---- .../influxdb_exporter/molecule/latest/tests/test_latest.py | 6 ++---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/roles/influxdb_exporter/meta/main.yml b/roles/influxdb_exporter/meta/main.yml index 32f4d0969..9e71c6430 100644 --- a/roles/influxdb_exporter/meta/main.yml +++ b/roles/influxdb_exporter/meta/main.yml @@ -9,14 +9,18 @@ galaxy_info: versions: - "focal" - "jammy" + - "noble" - name: "Debian" versions: - "bullseye" - - "buster" - name: "EL" versions: - "8" - "9" + - name: "Fedora" + versions: + - "39" + - "40" galaxy_tags: - "monitoring" - "prometheus" diff --git a/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py b/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py index 33196f0b7..6e2a73bc9 100644 --- a/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/influxdb_exporter/molecule/alternative/tests/test_alternative.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_service(host): diff --git a/roles/influxdb_exporter/molecule/default/tests/test_default.py b/roles/influxdb_exporter/molecule/default/tests/test_default.py index 822979c6c..c716b2c30 100644 --- a/roles/influxdb_exporter/molecule/default/tests/test_default.py +++ b/roles/influxdb_exporter/molecule/default/tests/test_default.py @@ -1,11 +1,9 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() def test_files(host): diff --git a/roles/influxdb_exporter/molecule/latest/tests/test_latest.py b/roles/influxdb_exporter/molecule/latest/tests/test_latest.py index 551edab40..0107d9cdb 100644 --- a/roles/influxdb_exporter/molecule/latest/tests/test_latest.py +++ b/roles/influxdb_exporter/molecule/latest/tests/test_latest.py @@ -1,12 +1,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os -import testinfra.utils.ansible_runner +from testinfra_helpers import get_target_hosts import pytest -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') +testinfra_hosts = get_target_hosts() @pytest.mark.parametrize("files", [ From 6532e4745e3b5d1067a9ab65d16d2676ebc5685e Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Fri, 18 Oct 2024 13:07:34 +0200 Subject: [PATCH 07/26] chore: refactor for _common role Signed-off-by: dobbi84 --- roles/influxdb_exporter/defaults/main.yml | 2 +- roles/influxdb_exporter/tasks/configure.yml | 29 ++++----- roles/influxdb_exporter/tasks/install.yml | 69 --------------------- roles/influxdb_exporter/tasks/main.yml | 34 +++++----- roles/influxdb_exporter/tasks/preflight.yml | 5 ++ roles/influxdb_exporter/tasks/selinux.yml | 12 ---- roles/influxdb_exporter/vars/main.yml | 2 + 7 files changed, 38 insertions(+), 115 deletions(-) delete mode 100644 roles/influxdb_exporter/tasks/install.yml delete mode 100644 roles/influxdb_exporter/tasks/selinux.yml diff --git a/roles/influxdb_exporter/defaults/main.yml b/roles/influxdb_exporter/defaults/main.yml index 20441ca7a..c74669d26 100644 --- a/roles/influxdb_exporter/defaults/main.yml +++ b/roles/influxdb_exporter/defaults/main.yml @@ -20,4 +20,4 @@ influxdb_exporter_system_group: "influxdb-exp" influxdb_exporter_system_user: "{{ influxdb_exporter_system_group }}" # Local path to stash the archive and its extraction -influxdb_exporter_archive_path: /tmp +influxdb_exporter_local_cache_path: /tmp diff --git a/roles/influxdb_exporter/tasks/configure.yml b/roles/influxdb_exporter/tasks/configure.yml index a6eb22674..c341aef4b 100644 --- a/roles/influxdb_exporter/tasks/configure.yml +++ b/roles/influxdb_exporter/tasks/configure.yml @@ -1,19 +1,12 @@ --- -- name: Copy the influxdb_exporter systemd service file - ansible.builtin.template: - src: influxdb_exporter.service.j2 - dest: /etc/systemd/system/influxdb_exporter.service - owner: root - group: root - mode: 0644 - notify: restart influxdb_exporter - -- name: Allow influxdb_exporter port in SELinux on RedHat OS family - community.general.seport: - ports: "{{ influxdb_exporter_web_listen_address.split(':')[-1] }}" - proto: tcp - setype: http_port_t - state: present - when: - - ansible_version.full is version_compare('2.4', '>=') - - ansible_selinux.status == "enabled" +- name: Configure + ansible.builtin.include_role: + name: prometheus.prometheus._common + tasks_from: configure.yml + vars: + _common_system_user: "{{ influxdb_exporter_system_user }}" + _common_system_group: "{{ influxdb_exporter_system_group }}" + tags: + - influxdb_exporter + - configure + - influxdb_exporter_configure diff --git a/roles/influxdb_exporter/tasks/install.yml b/roles/influxdb_exporter/tasks/install.yml deleted file mode 100644 index ad84ab474..000000000 --- a/roles/influxdb_exporter/tasks/install.yml +++ /dev/null @@ -1,69 +0,0 @@ ---- -- name: Create the influxdb_exporter group - ansible.builtin.group: - name: "{{ influxdb_exporter_system_group }}" - state: present - system: true - when: influxdb_exporter_system_group != "root" - -- name: Create the influxdb_exporter user - ansible.builtin.user: - name: "{{ influxdb_exporter_system_user }}" - groups: "{{ influxdb_exporter_system_group }}" - append: true - shell: /usr/sbin/nologin - system: true - create_home: false - home: / - when: influxdb_exporter_system_user != "root" - -- name: Get binary - when: - - influxdb_exporter_binary_local_dir | length == 0 - - not influxdb_exporter_skip_install - block: - - - name: Download influxdb_exporter binary to local folder - become: false - ansible.builtin.get_url: - url: "{{ influxdb_exporter_binary_url }}" - dest: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" - checksum: "sha256:{{ __influxdb_exporter_checksum }}" - mode: '0644' - register: _download_binary - until: _download_binary is succeeded - retries: 5 - delay: 2 - delegate_to: localhost - check_mode: false - - - name: Unpack influxdb_exporter binary - become: false - ansible.builtin.unarchive: - src: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" - dest: "{{ influxdb_exporter_archive_path }}" - creates: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}/influxdb_exporter" - delegate_to: localhost - check_mode: false - - - name: Propagate influxdb_exporter binaries - ansible.builtin.copy: - src: "{{ influxdb_exporter_archive_path }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}/influxdb_exporter" - dest: "{{ influxdb_exporter_binary_install_dir }}/influxdb_exporter" - mode: 0755 - owner: root - group: root - notify: restart influxdb_exporter - when: not ansible_check_mode - -- name: Propagate locally distributed influxdb_exporter binary - ansible.builtin.copy: - src: "{{ influxdb_exporter_binary_local_dir }}/influxdb_exporter" - dest: "{{ influxdb_exporter_binary_install_dir }}/influxdb_exporter" - mode: 0755 - owner: root - group: root - when: - - influxdb_exporter_binary_local_dir | length > 0 - - not influxdb_exporter_skip_install - notify: restart influxdb_exporter diff --git a/roles/influxdb_exporter/tasks/main.yml b/roles/influxdb_exporter/tasks/main.yml index d58543e08..bc1218634 100644 --- a/roles/influxdb_exporter/tasks/main.yml +++ b/roles/influxdb_exporter/tasks/main.yml @@ -13,29 +13,32 @@ - influxdb_exporter_run - name: Install - ansible.builtin.include_tasks: - file: install.yml - apply: - become: true - tags: - - influxdb_exporter_install - when: - ( not __influxdb_exporter_is_installed.stat.exists ) or - ( influxdb_exporter_binary_local_dir | length > 0 ) + ansible.builtin.include_role: + name: prometheus.prometheus._common + tasks_from: install.yml + vars: + _common_local_cache_path: "{{ influxdb_exporter_local_cache_path }}" + _common_binaries: "{{ _influxdb_exporter_binaries }}" + _common_binary_install_dir: "{{ influxdb_exporter_binary_install_dir }}" + _common_binary_url: "{{ influxdb_exporter_binary_url }}" + _common_checksums_url: "{{ influxdb_exporter_checksums_url }}" + _common_system_group: "{{ influxdb_exporter_system_group }}" + _common_system_user: "{{ influxdb_exporter_system_user }}" + _common_binary_unarchive_opts: ['--strip-components=1'] tags: - influxdb_exporter_install - name: SELinux - ansible.builtin.include_tasks: - file: selinux.yml - apply: - become: true - tags: - - influxdb_exporter_configure + ansible.builtin.include_role: + name: prometheus.prometheus._common + tasks_from: selinux.yml + vars: + _common_selinux_port: "{{ influxdb_exporter_web_listen_address | urlsplit('port') }}" when: ansible_selinux.status == "enabled" tags: - influxdb_exporter_configure + - name: Configure ansible.builtin.include_tasks: file: configure.yml @@ -57,3 +60,4 @@ - not ansible_check_mode tags: - influxdb_exporter_run + diff --git a/roles/influxdb_exporter/tasks/preflight.yml b/roles/influxdb_exporter/tasks/preflight.yml index 4c27fb433..eae6c951f 100644 --- a/roles/influxdb_exporter/tasks/preflight.yml +++ b/roles/influxdb_exporter/tasks/preflight.yml @@ -1,4 +1,9 @@ --- +- name: Common preflight + ansible.builtin.include_role: + name: prometheus.prometheus._common + tasks_from: preflight.yml + - name: Assert usage of systemd as an init system ansible.builtin.assert: that: ansible_service_mgr == 'systemd' diff --git a/roles/influxdb_exporter/tasks/selinux.yml b/roles/influxdb_exporter/tasks/selinux.yml deleted file mode 100644 index b8eff9b45..000000000 --- a/roles/influxdb_exporter/tasks/selinux.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- name: Install selinux python packages [RedHat] - ansible.builtin.package: - name: "{{ ['libselinux-python', 'policycoreutils-python'] - if ansible_python_version is version('3', '<') else - ['python3-libselinux', 'python3-policycoreutils'] }}" - state: present - register: _install_selinux_packages - until: _install_selinux_packages is success - retries: 5 - delay: 2 - when: ansible_os_family | lower == "redhat" diff --git a/roles/influxdb_exporter/vars/main.yml b/roles/influxdb_exporter/vars/main.yml index 4c7f04617..b75e80d31 100644 --- a/roles/influxdb_exporter/vars/main.yml +++ b/roles/influxdb_exporter/vars/main.yml @@ -9,3 +9,5 @@ go_arch_map: go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}" _influxdb_exporter_repo: "prometheus/influxdb_exporter" _influxdb_exporter_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}" + +_influxdb_exporter_binaries: ['influxdb_exporter'] From b4fc64528b5fb10290b24628da5671be0ff8586b Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:38:17 +0200 Subject: [PATCH 08/26] Update roles/influxdb_exporter/defaults/main.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/influxdb_exporter/defaults/main.yml b/roles/influxdb_exporter/defaults/main.yml index c74669d26..83bc80ae4 100644 --- a/roles/influxdb_exporter/defaults/main.yml +++ b/roles/influxdb_exporter/defaults/main.yml @@ -20,4 +20,4 @@ influxdb_exporter_system_group: "influxdb-exp" influxdb_exporter_system_user: "{{ influxdb_exporter_system_group }}" # Local path to stash the archive and its extraction -influxdb_exporter_local_cache_path: /tmp +influxdb_exporter_local_cache_path: "/tmp/influxdb_exporter-{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}/{{ influxdb_exporter_version }}" From 40fa0afcd36280d439f402a6f3a1ef8cd576e47e Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:40:26 +0200 Subject: [PATCH 09/26] Update roles/influxdb_exporter/molecule/alternative/molecule.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/molecule/alternative/molecule.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/influxdb_exporter/molecule/alternative/molecule.yml b/roles/influxdb_exporter/molecule/alternative/molecule.yml index 31fd870e5..724a68c14 100644 --- a/roles/influxdb_exporter/molecule/alternative/molecule.yml +++ b/roles/influxdb_exporter/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: From 9cd3949895732211a17fcd7fb6ca84fb32ef2721 Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:57:33 +0200 Subject: [PATCH 10/26] Update roles/influxdb_exporter/vars/main.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/vars/main.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/roles/influxdb_exporter/vars/main.yml b/roles/influxdb_exporter/vars/main.yml index b75e80d31..ad5a957a3 100644 --- a/roles/influxdb_exporter/vars/main.yml +++ b/roles/influxdb_exporter/vars/main.yml @@ -1,12 +1,9 @@ --- -go_arch_map: - i386: '386' - x86_64: 'amd64' - aarch64: 'arm64' - armv7l: 'armv7' - armv6l: 'armv6' - -go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}" +_influxdb_exporter_go_ansible_arch: "{{ {'i386': '386', + 'x86_64': 'amd64', + 'aarch64': 'arm64', + 'armv7l': 'armv7', + 'armv6l': 'armv6'}.get(ansible_architecture, ansible_architecture) }}" _influxdb_exporter_repo: "prometheus/influxdb_exporter" _influxdb_exporter_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}" From ccad1f4143fa2501fc357f688744cdfe10c58233 Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Fri, 18 Oct 2024 15:12:07 +0200 Subject: [PATCH 11/26] chore: fix post review on refactor for _commons role Signed-off-by: dobbi84 --- roles/influxdb_exporter/defaults/main.yml | 1 - .../influxdb_exporter/meta/argument_specs.yml | 5 --- .../molecule/alternative/molecule.yml | 1 - .../molecule/alternative/prepare.yml | 35 ------------------- roles/influxdb_exporter/tasks/configure.yml | 12 ------- roles/influxdb_exporter/tasks/main.yml | 30 +++++++++------- roles/influxdb_exporter/tasks/preflight.yml | 28 +++++++++++++-- 7 files changed, 44 insertions(+), 68 deletions(-) delete mode 100644 roles/influxdb_exporter/molecule/alternative/prepare.yml delete mode 100644 roles/influxdb_exporter/tasks/configure.yml diff --git a/roles/influxdb_exporter/defaults/main.yml b/roles/influxdb_exporter/defaults/main.yml index 83bc80ae4..f4294ae07 100644 --- a/roles/influxdb_exporter/defaults/main.yml +++ b/roles/influxdb_exporter/defaults/main.yml @@ -1,6 +1,5 @@ --- influxdb_exporter_version: "0.11.5" -influxdb_exporter_binary_local_dir: "" influxdb_exporter_binary_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/\ influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" influxdb_exporter_checksums_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/sha256sums.txt" diff --git a/roles/influxdb_exporter/meta/argument_specs.yml b/roles/influxdb_exporter/meta/argument_specs.yml index 9f980e7b5..9a4da7cb5 100644 --- a/roles/influxdb_exporter/meta/argument_specs.yml +++ b/roles/influxdb_exporter/meta/argument_specs.yml @@ -15,11 +15,6 @@ argument_specs: description: "influxdb exporter installation tasks gets skipped when set to true." type: bool default: false - influxdb_exporter_binary_local_dir: - description: - - "Enables the use of local packages instead of those distributed on github." - - "The parameter may be set to a directory where the C(influxdb_exporter) binary is stored on the host where ansible is run." - - "This overrides the I(influxdb_exporter_version) parameter" influxdb_exporter_binary_url: description: "URL of the influxdb exporter binaries .tar.gz file" default: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" diff --git a/roles/influxdb_exporter/molecule/alternative/molecule.yml b/roles/influxdb_exporter/molecule/alternative/molecule.yml index 724a68c14..04c01ee30 100644 --- a/roles/influxdb_exporter/molecule/alternative/molecule.yml +++ b/roles/influxdb_exporter/molecule/alternative/molecule.yml @@ -5,7 +5,6 @@ provisioner: inventory: group_vars: all: - influxdb_exporter_binary_local_dir: "/tmp/influxdb_exporter-linux-amd64" influxdb_exporter_web_listen_address: '127.0.0.1:8080' go_arch: amd64 diff --git a/roles/influxdb_exporter/molecule/alternative/prepare.yml b/roles/influxdb_exporter/molecule/alternative/prepare.yml deleted file mode 100644 index 772b9f6c7..000000000 --- a/roles/influxdb_exporter/molecule/alternative/prepare.yml +++ /dev/null @@ -1,35 +0,0 @@ ---- -- name: Run local preparation - hosts: localhost - gather_facts: false - tasks: - - name: Download influxdb_exporter binary to local folder - become: false - ansible.builtin.get_url: - url: "https://github.com/prometheus/influxdb_exporter/releases/download/v{{\ - \ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{\ - \ go_arch }}.tar.gz" - dest: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" - mode: 0644 - register: _download_binary - until: _download_binary is succeeded - retries: 5 - delay: 2 - check_mode: false - - - name: Unpack influxdb_exporter binary - become: false - ansible.builtin.unarchive: - src: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" - dest: "/tmp" - creates: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch\ - \ }}/influxdb_exporter" - check_mode: false - - - name: Link to influxdb_exporter binaries directory - become: false - ansible.builtin.file: - src: "/tmp/influxdb_exporter-{{ influxdb_exporter_version }}.linux-amd64" - dest: "/tmp/influxdb_exporter-linux-amd64" - state: link - check_mode: false diff --git a/roles/influxdb_exporter/tasks/configure.yml b/roles/influxdb_exporter/tasks/configure.yml deleted file mode 100644 index c341aef4b..000000000 --- a/roles/influxdb_exporter/tasks/configure.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- name: Configure - ansible.builtin.include_role: - name: prometheus.prometheus._common - tasks_from: configure.yml - vars: - _common_system_user: "{{ influxdb_exporter_system_user }}" - _common_system_group: "{{ influxdb_exporter_system_group }}" - tags: - - influxdb_exporter - - configure - - influxdb_exporter_configure diff --git a/roles/influxdb_exporter/tasks/main.yml b/roles/influxdb_exporter/tasks/main.yml index bc1218634..56d58e250 100644 --- a/roles/influxdb_exporter/tasks/main.yml +++ b/roles/influxdb_exporter/tasks/main.yml @@ -2,12 +2,11 @@ - name: Preflight ansible.builtin.include_tasks: file: preflight.yml - apply: - tags: - - influxdb_exporter_install - - influxdb_exporter_configure - - influxdb_exporter_run tags: + - influxdb_exporter + - install + - configure + - run - influxdb_exporter_install - influxdb_exporter_configure - influxdb_exporter_run @@ -26,6 +25,8 @@ _common_system_user: "{{ influxdb_exporter_system_user }}" _common_binary_unarchive_opts: ['--strip-components=1'] tags: + - influxdb_exporter + - install - influxdb_exporter_install - name: SELinux @@ -36,17 +37,20 @@ _common_selinux_port: "{{ influxdb_exporter_web_listen_address | urlsplit('port') }}" when: ansible_selinux.status == "enabled" tags: + - influxdb_exporter + - configure - influxdb_exporter_configure - - name: Configure - ansible.builtin.include_tasks: - file: configure.yml - apply: - become: true - tags: - - influxdb_exporter_configure + ansible.builtin.include_role: + name: prometheus.prometheus._common + tasks_from: configure.yml + vars: + _common_system_user: "{{ influxdb_exporter_system_user }}" + _common_system_group: "{{ influxdb_exporter_system_group }}" tags: + - influxdb_exporter + - configure - influxdb_exporter_configure - name: Ensure Influxdb Exporter is enabled on boot @@ -59,5 +63,7 @@ when: - not ansible_check_mode tags: + - influxdb_exporter + - run - influxdb_exporter_run diff --git a/roles/influxdb_exporter/tasks/preflight.yml b/roles/influxdb_exporter/tasks/preflight.yml index eae6c951f..c26693e78 100644 --- a/roles/influxdb_exporter/tasks/preflight.yml +++ b/roles/influxdb_exporter/tasks/preflight.yml @@ -3,11 +3,19 @@ ansible.builtin.include_role: name: prometheus.prometheus._common tasks_from: preflight.yml + tags: + - influxdb_exporter + - preflight + - influxdb_exporter_preflight - name: Assert usage of systemd as an init system ansible.builtin.assert: that: ansible_service_mgr == 'systemd' msg: "This role only works with systemd" + tags: + - influxdb_exporter + - preflight + - influxdb_exporter_preflight - name: Naive assertion of proper listen address ansible.builtin.assert: @@ -18,6 +26,10 @@ reject('match', '.+:\\d+$') | list | length == 0 + tags: + - influxdb_exporter + - preflight + - influxdb_exporter_preflight - name: Check if influxdb_exporter is installed ansible.builtin.stat: @@ -25,6 +37,8 @@ register: __influxdb_exporter_is_installed check_mode: false tags: + - influxdb_exporter + - install - influxdb_exporter_install - name: Discover latest version @@ -36,12 +50,16 @@ retries: 10 when: - influxdb_exporter_version == "latest" - - influxdb_exporter_binary_local_dir | length == 0 - not influxdb_exporter_skip_install + tags: + - influxdb_exporter + - install + - influxdb_exporter_install + - download + - influxdb_exporter_download - name: Get influxdb_exporter binary checksum when: - - influxdb_exporter_binary_local_dir | length == 0 - not influxdb_exporter_skip_install block: - name: Get checksum list from github @@ -57,3 +75,9 @@ with_items: "{{ __influxdb_exporter_checksums }}" when: - "('linux-' + go_arch + '.tar.gz') in item" + tags: + - influxdb_exporter + - install + - influxdb_exporter_install + - download + - influxdb_exporter_download From 48ac76f0f9a9bb26e7c8382944aa914b23d20498 Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:19:32 +0200 Subject: [PATCH 12/26] Update roles/influxdb_exporter/molecule/alternative/molecule.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/molecule/alternative/molecule.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/roles/influxdb_exporter/molecule/alternative/molecule.yml b/roles/influxdb_exporter/molecule/alternative/molecule.yml index 04c01ee30..890224131 100644 --- a/roles/influxdb_exporter/molecule/alternative/molecule.yml +++ b/roles/influxdb_exporter/molecule/alternative/molecule.yml @@ -7,5 +7,4 @@ provisioner: all: influxdb_exporter_web_listen_address: '127.0.0.1:8080' - go_arch: amd64 influxdb_exporter_version: 0.11.2 From 941bc4dc4686c52de299215e5467219d5ebd2e17 Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:19:38 +0200 Subject: [PATCH 13/26] Update roles/influxdb_exporter/defaults/main.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/influxdb_exporter/defaults/main.yml b/roles/influxdb_exporter/defaults/main.yml index f4294ae07..2b8cbc66e 100644 --- a/roles/influxdb_exporter/defaults/main.yml +++ b/roles/influxdb_exporter/defaults/main.yml @@ -1,7 +1,7 @@ --- influxdb_exporter_version: "0.11.5" influxdb_exporter_binary_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/\ - influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" + influxdb_exporter-{{ influxdb_exporter_version }}.{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}.tar.gz" influxdb_exporter_checksums_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/sha256sums.txt" influxdb_exporter_skip_install: false From 39af89660f4538a9d5ba092025209b06057d0999 Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:19:45 +0200 Subject: [PATCH 14/26] Update roles/influxdb_exporter/meta/argument_specs.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/meta/argument_specs.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/roles/influxdb_exporter/meta/argument_specs.yml b/roles/influxdb_exporter/meta/argument_specs.yml index 9a4da7cb5..3da88a913 100644 --- a/roles/influxdb_exporter/meta/argument_specs.yml +++ b/roles/influxdb_exporter/meta/argument_specs.yml @@ -11,10 +11,6 @@ argument_specs: influxdb_exporter_version: description: "influxdb exporter package version. Also accepts latest as parameter." default: "0.11.5" - influxdb_exporter_skip_install: - description: "influxdb exporter installation tasks gets skipped when set to true." - type: bool - default: false influxdb_exporter_binary_url: description: "URL of the influxdb exporter binaries .tar.gz file" default: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" From dadbd12a252cda0708cf485b220c6fbd244c6e79 Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:19:52 +0200 Subject: [PATCH 15/26] Update roles/influxdb_exporter/meta/argument_specs.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/meta/argument_specs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/influxdb_exporter/meta/argument_specs.yml b/roles/influxdb_exporter/meta/argument_specs.yml index 3da88a913..aa783d19a 100644 --- a/roles/influxdb_exporter/meta/argument_specs.yml +++ b/roles/influxdb_exporter/meta/argument_specs.yml @@ -58,6 +58,6 @@ argument_specs: - "I(Advanced)" - "influxdb exporter user" default: "influxdb-exp" - influxdb_exporter_archive_path: + influxdb_exporter_local_cache_path: description: 'Local path to stash the archive and its extraction' - default: "/tmp" + default: "/tmp/influxdb_exporter-{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}/{{ influxdb_exporter_version }}"" From a34152974846d38aa1c4703e0b1c26a999b54044 Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:19:59 +0200 Subject: [PATCH 16/26] Update roles/influxdb_exporter/meta/main.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/meta/main.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/roles/influxdb_exporter/meta/main.yml b/roles/influxdb_exporter/meta/main.yml index 9e71c6430..d1ba9cbac 100644 --- a/roles/influxdb_exporter/meta/main.yml +++ b/roles/influxdb_exporter/meta/main.yml @@ -17,10 +17,6 @@ galaxy_info: versions: - "8" - "9" - - name: "Fedora" - versions: - - "39" - - "40" galaxy_tags: - "monitoring" - "prometheus" From cc8cfda920e2f8d202f97b5f4c4e276e5a89adfe Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:20:24 +0200 Subject: [PATCH 17/26] Update roles/influxdb_exporter/tasks/preflight.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/tasks/preflight.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/roles/influxdb_exporter/tasks/preflight.yml b/roles/influxdb_exporter/tasks/preflight.yml index c26693e78..71f245139 100644 --- a/roles/influxdb_exporter/tasks/preflight.yml +++ b/roles/influxdb_exporter/tasks/preflight.yml @@ -50,7 +50,6 @@ retries: 10 when: - influxdb_exporter_version == "latest" - - not influxdb_exporter_skip_install tags: - influxdb_exporter - install From 776211cfcbb55339e6a08767f5ba13541efeb6e6 Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:20:38 +0200 Subject: [PATCH 18/26] Update roles/influxdb_exporter/tasks/preflight.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/tasks/preflight.yml | 24 --------------------- 1 file changed, 24 deletions(-) diff --git a/roles/influxdb_exporter/tasks/preflight.yml b/roles/influxdb_exporter/tasks/preflight.yml index 71f245139..b0a1476aa 100644 --- a/roles/influxdb_exporter/tasks/preflight.yml +++ b/roles/influxdb_exporter/tasks/preflight.yml @@ -56,27 +56,3 @@ - influxdb_exporter_install - download - influxdb_exporter_download - -- name: Get influxdb_exporter binary checksum - when: - - not influxdb_exporter_skip_install - block: - - name: Get checksum list from github - ansible.builtin.set_fact: - __influxdb_exporter_checksums: "{{ lookup('url', influxdb_exporter_checksums_url, headers=_influxdb_exporter_github_api_headers, wantlist=True) | list }}" - run_once: true - until: __influxdb_exporter_checksums is search('linux-' + go_arch + '.tar.gz') - retries: 10 - - - name: "Get checksum for {{ go_arch }}" - ansible.builtin.set_fact: - __influxdb_exporter_checksum: "{{ item.split(' ')[0] }}" - with_items: "{{ __influxdb_exporter_checksums }}" - when: - - "('linux-' + go_arch + '.tar.gz') in item" - tags: - - influxdb_exporter - - install - - influxdb_exporter_install - - download - - influxdb_exporter_download From 894efb44a11c7ff17467848b83457dfcc2f92dc2 Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:21:05 +0200 Subject: [PATCH 19/26] Update roles/influxdb_exporter/tasks/preflight.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/tasks/preflight.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/roles/influxdb_exporter/tasks/preflight.yml b/roles/influxdb_exporter/tasks/preflight.yml index b0a1476aa..938f1d55c 100644 --- a/roles/influxdb_exporter/tasks/preflight.yml +++ b/roles/influxdb_exporter/tasks/preflight.yml @@ -31,16 +31,6 @@ - preflight - influxdb_exporter_preflight -- name: Check if influxdb_exporter is installed - ansible.builtin.stat: - path: "{{ influxdb_exporter_binary_install_dir }}/influxdb_exporter" - register: __influxdb_exporter_is_installed - check_mode: false - tags: - - influxdb_exporter - - install - - influxdb_exporter_install - - name: Discover latest version ansible.builtin.set_fact: influxdb_exporter_version: "{{ (lookup('url', 'https://api.github.com/repos/{{ _influxdb_exporter_repo }}/releases/latest', headers=_influxdb_exporter_github_api_headers, From e13fd003da852ea72fb1d55e4bc8a41f76a92ae8 Mon Sep 17 00:00:00 2001 From: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:22:06 +0200 Subject: [PATCH 20/26] Update roles/influxdb_exporter/meta/argument_specs.yml Co-authored-by: gardar Signed-off-by: Davide Obbi <126786027+dobbi84@users.noreply.github.com> Signed-off-by: dobbi84 --- roles/influxdb_exporter/meta/argument_specs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/influxdb_exporter/meta/argument_specs.yml b/roles/influxdb_exporter/meta/argument_specs.yml index aa783d19a..641669da5 100644 --- a/roles/influxdb_exporter/meta/argument_specs.yml +++ b/roles/influxdb_exporter/meta/argument_specs.yml @@ -13,7 +13,7 @@ argument_specs: default: "0.11.5" influxdb_exporter_binary_url: description: "URL of the influxdb exporter binaries .tar.gz file" - default: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.linux-{{ go_arch }}.tar.gz" + default: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/influxdb_exporter-{{ influxdb_exporter_version }}.{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}.tar.gz" influxdb_exporter_checksums_url: description: "URL of the influxdb exporter checksums file" default: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/sha256sums.txt" From 031b5c3ded4c4665eff061596f190c1beb813938 Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Fri, 18 Oct 2024 17:52:56 +0200 Subject: [PATCH 21/26] chore: linter Signed-off-by: dobbi84 --- roles/influxdb_exporter/defaults/main.yml | 1 - roles/influxdb_exporter/tasks/main.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/roles/influxdb_exporter/defaults/main.yml b/roles/influxdb_exporter/defaults/main.yml index 2b8cbc66e..47c76b04d 100644 --- a/roles/influxdb_exporter/defaults/main.yml +++ b/roles/influxdb_exporter/defaults/main.yml @@ -3,7 +3,6 @@ influxdb_exporter_version: "0.11.5" influxdb_exporter_binary_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/\ influxdb_exporter-{{ influxdb_exporter_version }}.{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}.tar.gz" influxdb_exporter_checksums_url: "https://github.com/{{ _influxdb_exporter_repo }}/releases/download/v{{ influxdb_exporter_version }}/sha256sums.txt" -influxdb_exporter_skip_install: false influxdb_exporter_web_listen_address: "0.0.0.0:9122" influxdb_exporter_udp_bind_address: "{{ influxdb_exporter_web_listen_address }}" diff --git a/roles/influxdb_exporter/tasks/main.yml b/roles/influxdb_exporter/tasks/main.yml index 56d58e250..3466f0e71 100644 --- a/roles/influxdb_exporter/tasks/main.yml +++ b/roles/influxdb_exporter/tasks/main.yml @@ -66,4 +66,3 @@ - influxdb_exporter - run - influxdb_exporter_run - From 6533e31eeaeca1d6c337e972cd6da86b54b8f293 Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Fri, 18 Oct 2024 18:02:46 +0200 Subject: [PATCH 22/26] chore: linter Signed-off-by: dobbi84 --- roles/influxdb_exporter/meta/argument_specs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/influxdb_exporter/meta/argument_specs.yml b/roles/influxdb_exporter/meta/argument_specs.yml index 641669da5..7145f41c1 100644 --- a/roles/influxdb_exporter/meta/argument_specs.yml +++ b/roles/influxdb_exporter/meta/argument_specs.yml @@ -60,4 +60,4 @@ argument_specs: default: "influxdb-exp" influxdb_exporter_local_cache_path: description: 'Local path to stash the archive and its extraction' - default: "/tmp/influxdb_exporter-{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}/{{ influxdb_exporter_version }}"" + default: "/tmp/influxdb_exporter-{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}/{{ influxdb_exporter_version }}" From 2d418a3d6490ae2e44398d852a4e150573959b59 Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Fri, 18 Oct 2024 18:16:15 +0200 Subject: [PATCH 23/26] fix: include config dir otherwise commons uses root Signed-off-by: dobbi84 --- roles/influxdb_exporter/defaults/main.yml | 1 + roles/influxdb_exporter/tasks/main.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/roles/influxdb_exporter/defaults/main.yml b/roles/influxdb_exporter/defaults/main.yml index 47c76b04d..394fcf84b 100644 --- a/roles/influxdb_exporter/defaults/main.yml +++ b/roles/influxdb_exporter/defaults/main.yml @@ -17,5 +17,6 @@ influxdb_exporter_binary_install_dir: "/usr/local/bin" influxdb_exporter_system_group: "influxdb-exp" influxdb_exporter_system_user: "{{ influxdb_exporter_system_group }}" +influxdb_exporter_config_dir: "/etc/influxdb_exporter" # Local path to stash the archive and its extraction influxdb_exporter_local_cache_path: "/tmp/influxdb_exporter-{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}/{{ influxdb_exporter_version }}" diff --git a/roles/influxdb_exporter/tasks/main.yml b/roles/influxdb_exporter/tasks/main.yml index 3466f0e71..e244bff0b 100644 --- a/roles/influxdb_exporter/tasks/main.yml +++ b/roles/influxdb_exporter/tasks/main.yml @@ -23,6 +23,7 @@ _common_checksums_url: "{{ influxdb_exporter_checksums_url }}" _common_system_group: "{{ influxdb_exporter_system_group }}" _common_system_user: "{{ influxdb_exporter_system_user }}" + _common_config_dir: "{{ influxdb_exporter_config_dir }}" _common_binary_unarchive_opts: ['--strip-components=1'] tags: - influxdb_exporter From b82722cbd675cd3ea9fa752c1679d86841c77408 Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Fri, 18 Oct 2024 18:23:02 +0200 Subject: [PATCH 24/26] chore: lint spec file Signed-off-by: dobbi84 --- roles/influxdb_exporter/meta/argument_specs.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/roles/influxdb_exporter/meta/argument_specs.yml b/roles/influxdb_exporter/meta/argument_specs.yml index 7145f41c1..143fe2307 100644 --- a/roles/influxdb_exporter/meta/argument_specs.yml +++ b/roles/influxdb_exporter/meta/argument_specs.yml @@ -61,3 +61,6 @@ argument_specs: influxdb_exporter_local_cache_path: description: 'Local path to stash the archive and its extraction' default: "/tmp/influxdb_exporter-{{ ansible_system | lower }}-{{ _influxdb_exporter_go_ansible_arch }}/{{ influxdb_exporter_version }}" + influxdb_exporter_config_dir: + description: "Path to directory with influxdb_exporter configuration" + default: "/etc/influxdb_exporter" From 552115a917c2ca765371488793b27b896d9303ee Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Fri, 18 Oct 2024 19:38:38 +0200 Subject: [PATCH 25/26] chore: fix test default with correct home Signed-off-by: dobbi84 --- roles/influxdb_exporter/molecule/default/tests/test_default.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/influxdb_exporter/molecule/default/tests/test_default.py b/roles/influxdb_exporter/molecule/default/tests/test_default.py index c716b2c30..84cf40ab1 100644 --- a/roles/influxdb_exporter/molecule/default/tests/test_default.py +++ b/roles/influxdb_exporter/molecule/default/tests/test_default.py @@ -36,7 +36,7 @@ def test_user(host): assert host.group("influxdb-exp").exists assert "influxdb-exp" in host.user("influxdb-exp").groups assert host.user("influxdb-exp").shell == "/usr/sbin/nologin" - assert host.user("influxdb-exp").home == "/" + assert host.user("influxdb-exp").home == "/etc/influxdb_exporter" def test_service(host): From 73b4b702cbbbcdf44e738a3c5226e1d39d79c14f Mon Sep 17 00:00:00 2001 From: dobbi84 Date: Sat, 19 Oct 2024 08:43:04 +0200 Subject: [PATCH 26/26] docs: update influxdb/README Signed-off-by: dobbi84 --- roles/influxdb_exporter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/influxdb_exporter/README.md b/roles/influxdb_exporter/README.md index 887014929..ed3df3b74 100644 --- a/roles/influxdb_exporter/README.md +++ b/roles/influxdb_exporter/README.md @@ -2,7 +2,7 @@ ## Description -Deploy prometheus [influxdb exporter](https://github.com/prometheus/influxdb_exporter) using ansible. +Deploy prometheus [Influxdb exporter](https://github.com/prometheus/influxdb_exporter) using ansible. ## Requirements