diff --git a/roles/consul_exporter/README.md b/roles/consul_exporter/README.md new file mode 100644 index 000000000..0fbad19e9 --- /dev/null +++ b/roles/consul_exporter/README.md @@ -0,0 +1,83 @@ +

graph logo

+ +# Ansible Role: consul_exporter + +## Description + +Deploy prometheus [consul_exporter](https://github.com/prometheus/consul_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`) +- Passlib is required when using the basic authentication feature (`pip install passlib[bcrypt]`) + +## 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/consul_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.consul_exporter +``` + +### TLS config + +Before running consul_exporter role, the user needs to provision their own certificate and key. +```yaml +- hosts: all + pre_tasks: + - name: Create consul_exporter cert dir + file: + path: "/etc/consul_exporter" + state: directory + owner: root + group: root + + - name: Create cert and key + openssl_certificate: + path: /etc/consul_exporter/tls.cert + csr_path: /etc/consul_exporter/tls.csr + privatekey_path: /etc/consul_exporter/tls.key + provider: selfsigned + roles: + - prometheus.prometheus.consul_exporter + vars: + consul_exporter_tls_server_config: + cert_file: /etc/consul_exporter/tls.cert + key_file: /etc/consul_exporter/tls.key + consul_exporter_basic_auth_users: + randomuser: examplepassword +``` + + +### 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/superq/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/consul_exporter/TROUBLESHOOTING.md b/roles/consul_exporter/TROUBLESHOOTING.md new file mode 100644 index 000000000..0bece12af --- /dev/null +++ b/roles/consul_exporter/TROUBLESHOOTING.md @@ -0,0 +1,20 @@ +# Troubleshooting + +## Bad requests (HTTP 400) + +This role downloads checksums from the Github project to verify the integrity of artifacts installed on your servers. When downloading the checksums, a "bad request" error might occur. + +This happens in environments which (knowningly or unknowling) use the [netrc mechanism](https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html) to auto-login into servers. + +Unless netrc is needed by your playbook and ansible roles, please unset the var like so: + +``` +$ NETRC= ansible-playbook ... +``` + +Or: + +``` +$ export NETRC= +$ ansible-playbook ... +``` diff --git a/roles/consul_exporter/defaults/main.yml b/roles/consul_exporter/defaults/main.yml new file mode 100644 index 000000000..736adfb9d --- /dev/null +++ b/roles/consul_exporter/defaults/main.yml @@ -0,0 +1,38 @@ +--- +consul_exporter_version: 0.13.0 +consul_exporter_binary_url: "https://github.com/{{ _consul_exporter_repo }}/releases/download/v{{ consul_exporter_version }}/\ + consul_exporter-{{ consul_exporter_version }}.{{ ansible_facts['system'] | lower }}-{{ _consul_exporter_go_ansible_arch }}.tar.gz" +consul_exporter_checksums_url: "https://github.com/{{ _consul_exporter_repo }}/releases/download/v{{ consul_exporter_version }}/sha256sums.txt" + +consul_exporter_web_listen_address: "0.0.0.0:9107" +consul_exporter_web_telemetry_path: "/metrics" + +consul_exporter_tls_server_config: {} + +consul_exporter_http_server_config: {} + +consul_exporter_basic_auth_users: {} + +consul_exporter_server: "http://localhost:8500" +consul_exporter_timeout: "500ms" +consul_exporter_request_limit: 0 +consul_exporter_kv_prefix: "" +consul_exporter_kv_filter: "" +consul_exporter_meta_filter: "" +consul_exporter_health_summary: false +consul_exporter_agent_only: false +consul_exporter_allow_stale: false +consul_exporter_require_consistent: false + +consul_exporter_log_level: "info" +consul_exporter_log_format: "logfmt" + +consul_exporter_system_user: "consul-exp" +consul_exporter_system_group: "{{ consul_exporter_system_user }}" + + +# Local path to stash the archive and its extraction +consul_exporter_local_cache_path: "/tmp/consul_exporter-{{ ansible_facts['system'] | lower }}-{{ _consul_exporter_go_ansible_arch }}/{{ consul_exporter_version }}" + +consul_exporter_binary_install_dir: "/usr/local/bin" +consul_exporter_config_dir: "/etc/consul_exporter" diff --git a/roles/consul_exporter/handlers/main.yml b/roles/consul_exporter/handlers/main.yml new file mode 100644 index 000000000..9e0080f53 --- /dev/null +++ b/roles/consul_exporter/handlers/main.yml @@ -0,0 +1,10 @@ +--- +- name: Restart consul_exporter + listen: "restart consul_exporter" + become: true + ansible.builtin.systemd: + daemon_reload: true + name: consul_exporter + state: restarted + when: + - not ansible_check_mode diff --git a/roles/consul_exporter/meta/argument_specs.yml b/roles/consul_exporter/meta/argument_specs.yml new file mode 100644 index 000000000..98d63ac2d --- /dev/null +++ b/roles/consul_exporter/meta/argument_specs.yml @@ -0,0 +1,106 @@ +--- +# yamllint disable rule:line-length +argument_specs: + main: + short_description: "Prometheus consul Exporter" + description: + - "Deploy prometheus L(consul_exporter,https://github.com/prometheus/consul_exporter) using ansible" + author: + - "Prometheus Community" + options: + consul_exporter_version: + description: "consul exporter package version. Also accepts latest as parameter." + default: "0.13.0" + consul_exporter_binary_url: + description: "URL of the consul_exporter binaries .tar.gz file" + default: "https://github.com/{{ _consul_exporter_repo }}/releases/download/v{{ consul_exporter_version }}/consul_exporter-{{ consul_exporter_version }}.{{ ansible_facts['system'] | lower }}-{{ _consul_exporter_go_ansible_arch }}.tar.gz" + consul_exporter_checksums_url: + description: "URL of the consul_exporter checksums file" + default: "https://github.com/{{ _consul_exporter_repo }}/releases/download/v{{ consul_exporter_version }}/sha256sums.txt" + consul_exporter_web_listen_address: + description: "Address on which consul_exporter will listen" + default: "0.0.0.0:9107" + consul_exporter_web_telemetry_path: + description: "Path under which to expose metrics" + default: "/metrics" + consul_exporter_tls_server_config: + description: + - "Configuration for TLS authentication." + - "Keys and values are the same as in L(consul_exporter docs,https://github.com/superq/consul_exporter/blob/master/https/README.md#sample-config)." + type: "dict" + consul_exporter_http_server_config: + description: + - "Config for HTTP/2 support." + - "Keys and values are the same as in L(consul_exporter docs,https://github.com/superq/consul_exporter/blob/master/https/README.md#sample-config)." + type: "dict" + consul_exporter_basic_auth_users: + description: "Dictionary of users and password for basic authentication. Passwords are automatically hashed with bcrypt." + type: "dict" + consul_exporter_log_level: + description: "Only log messages with the given severity or above" + default: "info" + choices: + - "debug" + - "info" + - "warn" + - "error" + consul_exporter_log_format: + description: "Output format of log messages" + default: "logfmt" + choices: + - "logfmt" + - "json" + + consul_exporter_server: + description: "HTTP API address of a Consul server or agent." + default: "http://localhost:8500" + consul_exporter_timeout: + description: "Timeout on HTTP requests to the Consul API" + default: "500ms" + consul_exporter_request_limit: + description: "Limit the maximum number of concurrent requests to consul, 0 means no limit" + default: 0 + consul_exporter_kv_prefix: + description: "Prefix from which to expose key/value pairs" + consul_exporter_kv_filter: + description: "Regex that determines which keys to expose" + consul_exporter_meta_filter: + description: "Regex that determines which meta keys to expose" + consul_exporter_health_summary: + description: "Generate a health summary for each service instance. Needs n+1 queries to collect all information." + type: bool + default: false + consul_exporter_agent_only: + description: "Only export metrics about services registered on local agent" + type: bool + default: false + consul_exporter_allow_stale: + description: "Allows any Consul server (non-leader) to service a read" + type: bool + default: false + consul_exporter_require_consistent: + description: "Forces the read to be fully consistent" + type: bool + default: false + + consul_exporter_system_group: + description: + - "I(Advanced)" + - "System group for consul_exporter" + default: "consul-exp" + consul_exporter_system_user: + description: + - "I(Advanced)" + - "consul exporter user" + default: "consul-exp" + consul_exporter_binary_install_dir: + description: + - "I(Advanced)" + - "Directory to install binaries" + default: "/usr/local/bin" + consul_exporter_local_cache_path: + description: 'Local path to stash the archive and its extraction' + default: "/tmp/consul_exporter-{{ ansible_facts['system'] | lower }}-{{ _consul_exporter_go_ansible_arch }}/{{ consul_exporter_version }}" + consul_exporter_config_dir: + description: "Path to directory with consul_exporter configuration" + default: "/etc/consul_exporter" diff --git a/roles/consul_exporter/meta/main.yml b/roles/consul_exporter/meta/main.yml new file mode 100644 index 000000000..206b9f1ed --- /dev/null +++ b/roles/consul_exporter/meta/main.yml @@ -0,0 +1,25 @@ +--- +galaxy_info: + author: "Prometheus Community" + description: "Prometheus Consul Exporter" + license: "Apache" + min_ansible_version: "2.9" + platforms: + - name: "Ubuntu" + versions: + - "focal" + - "jammy" + - "noble" + - name: "Debian" + versions: + - "bullseye" + - name: "EL" + versions: + - "8" + - "9" + galaxy_tags: + - "monitoring" + - "prometheus" + - "exporter" + - "metrics" + - "system" diff --git a/roles/consul_exporter/molecule/alternative/molecule.yml b/roles/consul_exporter/molecule/alternative/molecule.yml new file mode 100644 index 000000000..08a9a3c52 --- /dev/null +++ b/roles/consul_exporter/molecule/alternative/molecule.yml @@ -0,0 +1,19 @@ +--- +provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" + inventory: + group_vars: + all: + consul_exporter_version: 0.13.0 + consul_exporter_local_cache_path: "/tmp/consul_exporter-linux-amd64/{{ consul_exporter_version }}" + consul_exporter_web_listen_address: '127.0.1.1:8080' + consul_exporter_tls_server_config: + cert_file: /etc/consul_exporter/tls.cert + key_file: /etc/consul_exporter/tls.key + consul_exporter_http_server_config: + http2: true + consul_exporter_basic_auth_users: + randomuser: examplepassword + consul_exporter_binary_url: "https://github.com/prometheus/consul_exporter/releases/download/v{{ consul_exporter_version\ + \ }}/consul_exporter-{{ consul_exporter_version }}.linux-amd64.tar.gz" diff --git a/roles/consul_exporter/molecule/alternative/tests/test_alternative.py b/roles/consul_exporter/molecule/alternative/tests/test_alternative.py new file mode 100644 index 000000000..aa1008208 --- /dev/null +++ b/roles/consul_exporter/molecule/alternative/tests/test_alternative.py @@ -0,0 +1,43 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from testinfra_helpers import get_target_hosts +import pytest + +testinfra_hosts = get_target_hosts() + + +def test_directories(host): + dirs = [ + "/etc/consul_exporter" + ] + for dir in dirs: + d = host.file(dir) + assert d.is_directory + assert d.exists + + +def test_service(host): + s = host.service("consul_exporter") + try: + assert s.is_running + except AssertionError: + # Capture service logs + journal_output = host.run('journalctl -u consul_exporter --since "1 hour ago"') + print("\n==== journalctl -u consul_exporter Output ====\n") + print(journal_output) + print("\n============================================\n") + raise # Re-raise the original assertion error + + +def test_protecthome_property(host): + s = host.service("consul_exporter") + p = s.systemd_properties + assert p.get("ProtectHome") == "yes" + + +@pytest.mark.parametrize("sockets", [ + "tcp://127.0.1.1:8080", +]) +def test_socket(host, sockets): + assert host.socket(sockets).is_listening diff --git a/roles/consul_exporter/molecule/default/molecule.yml b/roles/consul_exporter/molecule/default/molecule.yml new file mode 100644 index 000000000..09fed491f --- /dev/null +++ b/roles/consul_exporter/molecule/default/molecule.yml @@ -0,0 +1,6 @@ +--- +provisioner: + inventory: + group_vars: + all: + consul_exporter_web_listen_address: "127.0.0.1:9107" diff --git a/roles/consul_exporter/molecule/default/tests/test_default.py b/roles/consul_exporter/molecule/default/tests/test_default.py new file mode 100644 index 000000000..2febaf36d --- /dev/null +++ b/roles/consul_exporter/molecule/default/tests/test_default.py @@ -0,0 +1,76 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from testinfra_helpers import get_target_hosts + +testinfra_hosts = get_target_hosts() + + +def test_directories(host): + dirs = [ + "/etc/consul_exporter" + ] + for dir in dirs: + d = host.file(dir) + assert d.is_directory + assert d.exists + + +def test_files(host): + files = [ + "/etc/systemd/system/consul_exporter.service", + "/usr/local/bin/consul_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("consul-exp").exists + assert "consul-exp" in host.user("consul-exp").groups + assert host.user("consul-exp").shell == "/usr/sbin/nologin" + + +def test_service(host): + s = host.service("consul_exporter") + try: + assert s.is_running + except AssertionError: + # Capture service logs + journal_output = host.run('journalctl -u consul_exporter --since "1 hour ago"') + print("\n==== journalctl -u consul_exporter Output ====\n") + print(journal_output) + print("\n============================================\n") + raise # Re-raise the original assertion error + + +def test_protecthome_property(host): + s = host.service("consul_exporter") + p = s.systemd_properties + assert p.get("ProtectHome") == "yes" + + +def test_socket(host): + sockets = [ + "tcp://127.0.0.1:9107" + ] + for socket in sockets: + s = host.socket(socket) + assert s.is_listening diff --git a/roles/consul_exporter/molecule/latest/molecule.yml b/roles/consul_exporter/molecule/latest/molecule.yml new file mode 100644 index 000000000..ba78fa7f3 --- /dev/null +++ b/roles/consul_exporter/molecule/latest/molecule.yml @@ -0,0 +1,6 @@ +--- +provisioner: + inventory: + group_vars: + all: + consul_exporter_version: latest diff --git a/roles/consul_exporter/molecule/latest/tests/test_alternative.py b/roles/consul_exporter/molecule/latest/tests/test_alternative.py new file mode 100644 index 000000000..a0405d3c2 --- /dev/null +++ b/roles/consul_exporter/molecule/latest/tests/test_alternative.py @@ -0,0 +1,41 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from testinfra_helpers import get_target_hosts +import pytest + +testinfra_hosts = get_target_hosts() + + +@pytest.mark.parametrize("files", [ + "/etc/systemd/system/consul_exporter.service", + "/usr/local/bin/consul_exporter" +]) +def test_files(host, files): + f = host.file(files) + assert f.exists + assert f.is_file + + +def test_service(host): + s = host.service("consul_exporter") + try: + assert s.is_running + except AssertionError: + # Capture service logs + journal_output = host.run('journalctl -u consul_exporter --since "1 hour ago"') + print("\n==== journalctl -u consul_exporter Output ====\n") + print(journal_output) + print("\n============================================\n") + raise # Re-raise the original assertion error + + +def test_protecthome_property(host): + s = host.service("consul_exporter") + p = s.systemd_properties + assert p.get("ProtectHome") == "yes" + + +def test_socket(host): + s = host.socket("tcp://0.0.0.0:9107") + assert s.is_listening diff --git a/roles/consul_exporter/tasks/main.yml b/roles/consul_exporter/tasks/main.yml new file mode 100644 index 000000000..b55b939d6 --- /dev/null +++ b/roles/consul_exporter/tasks/main.yml @@ -0,0 +1,73 @@ +--- +- name: Preflight + ansible.builtin.include_tasks: + file: preflight.yml + tags: + - consul_exporter + - install + - configure + - run + - consul_exporter_install + - consul_exporter_configure + - consul_exporter_run + +- name: Install + ansible.builtin.include_role: + name: prometheus.prometheus._common + tasks_from: install.yml + vars: + _common_local_cache_path: "{{ consul_exporter_local_cache_path }}" + _common_binaries: "{{ _consul_exporter_binaries }}" + _common_binary_install_dir: "{{ consul_exporter_binary_install_dir }}" + _common_binary_url: "{{ consul_exporter_binary_url }}" + _common_checksums_url: "{{ consul_exporter_checksums_url }}" + _common_system_group: "{{ consul_exporter_system_group }}" + _common_system_user: "{{ consul_exporter_system_user }}" + _common_config_dir: "{{ consul_exporter_config_dir }}" + _common_binary_unarchive_opts: ['--strip-components=1'] + tags: + - consul_exporter + - install + - consul_exporter_install + +- name: SELinux + ansible.builtin.include_role: + name: prometheus.prometheus._common + tasks_from: selinux.yml + vars: + _common_selinux_port: "{{ consul_exporter_web_listen_address | urlsplit('port') }}" + when: ansible_facts['selinux'].status == "enabled" + tags: + - consul_exporter + - configure + - consul_exporter_configure + +- name: Configure + ansible.builtin.include_role: + name: prometheus.prometheus._common + tasks_from: configure.yml + vars: + _common_system_user: "{{ consul_exporter_system_user }}" + _common_system_group: "{{ consul_exporter_system_group }}" + _common_config_dir: "{{ consul_exporter_config_dir }}" + _common_tls_server_config: "{{ consul_exporter_tls_server_config }}" + _common_http_server_config: "{{ consul_exporter_http_server_config }}" + _common_basic_auth_users: "{{ consul_exporter_basic_auth_users }}" + tags: + - consul_exporter + - configure + - consul_exporter_configure + +- name: Ensure consul Exporter is enabled on boot + become: true + ansible.builtin.systemd: + daemon_reload: true + name: consul_exporter + enabled: true + state: started + when: + - not ansible_check_mode + tags: + - consul_exporter + - run + - consul_exporter_run diff --git a/roles/consul_exporter/tasks/preflight.yml b/roles/consul_exporter/tasks/preflight.yml new file mode 100644 index 000000000..b6755757c --- /dev/null +++ b/roles/consul_exporter/tasks/preflight.yml @@ -0,0 +1,56 @@ +--- +- name: Common preflight + ansible.builtin.include_role: + name: prometheus.prometheus._common + tasks_from: preflight.yml + vars: + _common_web_listen_address: "{{ consul_exporter_web_listen_address }}" + +- name: Assert that used version supports listen address type + ansible.builtin.assert: + that: + - >- + consul_exporter_web_listen_address is string + or + consul_exporter_web_listen_address | type_debug == "list" + +- name: Assert that TLS config is correct + when: consul_exporter_tls_server_config | length > 0 + block: + - name: Assert that TLS key and cert path are set + ansible.builtin.assert: + that: + - "consul_exporter_tls_server_config.cert_file is defined" + - "consul_exporter_tls_server_config.key_file is defined" + + - name: Check existence of TLS cert file + ansible.builtin.stat: + path: "{{ consul_exporter_tls_server_config.cert_file }}" + register: __consul_exporter_cert_file + + - name: Check existence of TLS key file + ansible.builtin.stat: + path: "{{ consul_exporter_tls_server_config.key_file }}" + register: __consul_exporter_key_file + + - name: Assert that TLS key and cert are present + ansible.builtin.assert: + that: + - "__consul_exporter_cert_file.stat.exists" + - "__consul_exporter_key_file.stat.exists" + +- name: Discover latest version + ansible.builtin.set_fact: + consul_exporter_version: "{{ (lookup('url', 'https://api.github.com/repos/{{ _consul_exporter_repo }}/releases/latest', headers=_github_api_headers, + split_lines=False) | from_json).get('tag_name') | replace('v', '') }}" + run_once: true + until: consul_exporter_version is version('0.0.0', '>=') + retries: 10 + when: + - consul_exporter_version == "latest" + tags: + - consul_exporter + - install + - consul_exporter_install + - download + - consul_exporter_download diff --git a/roles/consul_exporter/templates/consul_exporter.service.j2 b/roles/consul_exporter/templates/consul_exporter.service.j2 new file mode 100644 index 000000000..3a405949f --- /dev/null +++ b/roles/consul_exporter/templates/consul_exporter.service.j2 @@ -0,0 +1,70 @@ +{{ ansible_managed | comment }} + +[Unit] +Description=Prometheus Consul Exporter +After=network-online.target + +[Service] +Type=simple +User={{ consul_exporter_system_user }} +Group={{ consul_exporter_system_group }} +ExecStart={{ consul_exporter_binary_install_dir }}/consul_exporter \ +{% if consul_exporter_tls_server_config | length > 0 or consul_exporter_http_server_config | length > 0 or consul_exporter_basic_auth_users | length > 0 %} + '--web.config.file={{ consul_exporter_config_dir }}/web_config.yml' \ +{% endif %} + '--consul.server={{ consul_exporter_server }}' \ + '--consul.timeout={{ consul_exporter_timeout }}' \ + '--consul.request-limit={{ consul_exporter_request_limit }}' \ +{% if consul_exporter_kv_prefix | length > 0 %} + '--kv.prefix={{ consul_exporter_kv_prefix }}' \ +{% endif %} +{% if consul_exporter_kv_filter | length > 0 %} + '--kv.filter={{ consul_exporter_kv_filter }}' \ +{% endif %} +{% if consul_exporter_meta_filter | length > 0 %} + '--meta.filter={{ consul_exporter_meta_filter }}' \ +{% endif %} +{% if consul_exporter_health_summary %} + '--consul.health-summary' \ +{% else %} + '--no-consul.health-summary' \ +{% endif %} +{% if consul_exporter_agent_only %} + '--consul.agent-only' \ +{% else %} + '--no-consul.agent-only' \ +{% endif %} +{% if consul_exporter_allow_stale %} + '--consul.allow_stale' \ +{% else %} + '--no-consul.allow_stale' \ +{% endif %} +{% if consul_exporter_require_consistent %} + '--consul.require_consistent' \ +{% else %} + '--no-consul.require_consistent' \ +{% endif %} + '--web.listen-address={{ consul_exporter_web_listen_address }}' \ + '--web.telemetry-path={{ consul_exporter_web_telemetry_path }}' \ + '--log.level={{ consul_exporter_log_level }}' \ + '--log.format={{ consul_exporter_log_format }}' + +SyslogIdentifier=consul_exporter +Restart=always +RestartSec=1 +StartLimitInterval=0 + +ProtectHome=yes +NoNewPrivileges=yes + +{% if (ansible_facts.packages.systemd | first).version is version('232', '>=') %} +ProtectSystem=strict +ProtectControlGroups=true +ProtectKernelModules=true +ProtectKernelTunables=yes +{% else %} +ProtectSystem=full +{% endif %} + +[Install] +WantedBy=multi-user.target diff --git a/roles/consul_exporter/test-requirements.txt b/roles/consul_exporter/test-requirements.txt new file mode 100644 index 000000000..7f0b6e759 --- /dev/null +++ b/roles/consul_exporter/test-requirements.txt @@ -0,0 +1 @@ +bcrypt diff --git a/roles/consul_exporter/vars/main.yml b/roles/consul_exporter/vars/main.yml new file mode 100644 index 000000000..f7ff6abb2 --- /dev/null +++ b/roles/consul_exporter/vars/main.yml @@ -0,0 +1,9 @@ +--- +_consul_exporter_go_ansible_arch: "{{ {'i386': '386', + 'x86_64': 'amd64', + 'aarch64': 'arm64', + 'armv7l': 'armv7', + 'armv6l': 'armv6'}.get(ansible_facts['architecture'], ansible_facts['architecture']) }}" +_consul_exporter_repo: "prometheus/consul_exporter" +_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}" +_consul_exporter_binaries: ['consul_exporter'] diff --git a/tests/integration/targets/molecule-consul_exporter-alternative/runme.sh b/tests/integration/targets/molecule-consul_exporter-alternative/runme.sh new file mode 100755 index 000000000..d094c3e1b --- /dev/null +++ b/tests/integration/targets/molecule-consul_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-consul_exporter-default/runme.sh b/tests/integration/targets/molecule-consul_exporter-default/runme.sh new file mode 100755 index 000000000..d094c3e1b --- /dev/null +++ b/tests/integration/targets/molecule-consul_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-consul_exporter-latest/runme.sh b/tests/integration/targets/molecule-consul_exporter-latest/runme.sh new file mode 100755 index 000000000..d094c3e1b --- /dev/null +++ b/tests/integration/targets/molecule-consul_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"