diff --git a/.config/molecule/alternative/prepare.yml b/.config/molecule/alternative/prepare.yml new file mode 100644 index 00000000..1eeadc41 --- /dev/null +++ b/.config/molecule/alternative/prepare.yml @@ -0,0 +1,104 @@ +--- +- name: Run local preparation + hosts: localhost + gather_facts: false + vars: + __role_name: "{{ lookup('ansible.builtin.env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}" + __binary_name: "{{ __role_name }}" + __binary_url: "{{ lookup('ansible.builtin.vars', __role_name ~ '_binary_url') }}" + __binary_local_dir: "{{ lookup('ansible.builtin.vars', __role_name ~ '_binary_local_dir') }}" + __tls_server_config: "{{ lookup('ansible.builtin.vars', __role_name ~ '_tls_server_config', default={}) }}" + tasks: + - name: "Create local binary directory" + ansible.builtin.file: + path: "{{ __binary_local_dir }}" + state: directory + mode: 0755 + + - name: "Fetch binary" + become: false + ansible.builtin.unarchive: + src: "{{ __binary_url }}" + dest: "{{ __binary_local_dir }}" + remote_src: true + list_files: true + extra_opts: + - "--strip-components=1" + creates: "{{ __binary_local_dir }}/{{ __binary_name }}" + check_mode: false + register: __download_binary + + - name: Generate self signed certificates + when: "'cert_file' in __tls_server_config" + block: + - name: Install pyOpenSSL for certificate generation + ansible.builtin.pip: + name: "pyOpenSSL" + + - name: Create private key + community.crypto.openssl_privatekey: + path: "/tmp/tls.key" + + - name: Create CSR + community.crypto.openssl_csr: + path: "/tmp/tls.csr" + privatekey_path: "/tmp/tls.key" + + - name: Create certificate + community.crypto.x509_certificate: + path: "/tmp/tls.cert" + csr_path: "/tmp/tls.csr" + privatekey_path: "/tmp/tls.key" + provider: selfsigned + + - name: Filter out incompatible distro/ansible version combos + ansible.builtin.add_host: + name: "{{ item }}" + groups: target_hosts + loop: >- + {{ + groups['all'] + | map('extract', hostvars) + | rejectattr('exclude_ansible_vers', 'defined') + | map(attribute='inventory_hostname') + | list + | union( + groups['all'] + | map('extract', hostvars) + | selectattr('exclude_ansible_vers', 'defined') + | rejectattr('exclude_ansible_vers', 'search', ansible_version.major ~ '.' ~ ansible_version.minor) + | map(attribute='inventory_hostname') + | list + ) + }} + when: item not in groups['target_hosts'] + changed_when: false + +- name: Run target preparation + hosts: target_hosts + any_errors_fatal: true + vars: + __role_name: "{{ lookup('ansible.builtin.env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}" + __tls_server_config: "{{ lookup('ansible.builtin.vars', __role_name ~ '_tls_server_config', default={}) }}" + tasks: + - name: Copy self signed certificates + when: "'cert_file' in __tls_server_config" + block: + - name: "Create cert dir" + ansible.builtin.file: + path: "{{ __tls_server_config.cert_file | dirname }}" + state: directory + owner: root + group: root + mode: u+rwX,g+rwX,o=rX + + - name: "Copy cert and key" + ansible.builtin.copy: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + mode: "{{ item.mode | default('0644') }}" + loop: + - src: "/tmp/tls.cert" + dest: "{{ __tls_server_config.cert_file }}" + - src: "/tmp/tls.key" + dest: "{{ __tls_server_config.key_file }}" diff --git a/roles/alertmanager/molecule/alternative/molecule.yml b/roles/alertmanager/molecule/alternative/molecule.yml index fc61e33a..70f0d82d 100644 --- a/roles/alertmanager/molecule/alternative/molecule.yml +++ b/roles/alertmanager/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -34,3 +36,5 @@ provisioner: - "127.0.0.1:6783" - "alertmanager.demo.do.prometheus.io:6783" alertmanager_version: 0.25.0 + alertmanager_binary_url: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version\ + \ }}/alertmanager-{{ alertmanager_version }}.linux-amd64.tar.gz" diff --git a/roles/bind_exporter/molecule/alternative/molecule.yml b/roles/bind_exporter/molecule/alternative/molecule.yml index ad910d83..ddd0ed6f 100644 --- a/roles/bind_exporter/molecule/alternative/molecule.yml +++ b/roles/bind_exporter/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -19,3 +21,6 @@ provisioner: randomuser: examplepassword go_arch: amd64 bind_exporter_version: 0.7.0 + bind_exporter_binary_url: "https://github.com/prometheus-community/bind_exporter/releases/download/v{{\ + \ bind_exporter_version }}/bind_exporter-{{ bind_exporter_version\ + \ }}.linux-{{ go_arch }}.tar.gz" diff --git a/roles/cadvisor/molecule/alternative/molecule.yml b/roles/cadvisor/molecule/alternative/molecule.yml index 898ee4fd..50e63c38 100644 --- a/roles/cadvisor/molecule/alternative/molecule.yml +++ b/roles/cadvisor/molecule/alternative/molecule.yml @@ -1,8 +1,11 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: + cadvisor_binary_url: "https://github.com/google/cadvisor/releases/download/v{{ cadvisor_version }}/cadvisor-v{{ cadvisor_version }}-linux-{{ go_arch }}" cadvisor_binary_local_dir: "/tmp" cadvisor_port: "8000" go_arch: amd64 diff --git a/roles/chrony_exporter/molecule/alternative/molecule.yml b/roles/chrony_exporter/molecule/alternative/molecule.yml index 8f0fdf70..6e55e96e 100644 --- a/roles/chrony_exporter/molecule/alternative/molecule.yml +++ b/roles/chrony_exporter/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -11,7 +13,6 @@ provisioner: - sources chrony_exporter_disabled_collectors: - tracking - chrony_exporter_tls_server_config: cert_file: /etc/chrony_exporter/tls.cert key_file: /etc/chrony_exporter/tls.key @@ -21,3 +22,5 @@ provisioner: randomuser: examplepassword go_arch: amd64 chrony_exporter_version: 0.6.0 + chrony_exporter_binary_url: "https://github.com/superq/chrony_exporter/releases/download/v{{ chrony_exporter_version\ + \ }}/chrony_exporter-{{ chrony_exporter_version }}.linux-{{ go_arch }}.tar.gz" diff --git a/roles/fail2ban_exporter/molecule/alternative/molecule.yml b/roles/fail2ban_exporter/molecule/alternative/molecule.yml index 216671a4..182b6776 100644 --- a/roles/fail2ban_exporter/molecule/alternative/molecule.yml +++ b/roles/fail2ban_exporter/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -7,3 +9,5 @@ provisioner: fail2ban_exporter_web_listen_address: "127.0.1.1:9191" go_arch: amd64 fail2ban_exporter_version: 0.10.1 + fail2ban_exporter_binary_url: "https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/-/releases/v{{ fail2ban_exporter_version }}/downloads/\ + fail2ban_exporter_{{ fail2ban_exporter_version }}_linux_{{ go_arch }}.tar.gz" diff --git a/roles/ipmi_exporter/molecule/alternative/molecule.yml b/roles/ipmi_exporter/molecule/alternative/molecule.yml index 93942955..d997bc7f 100644 --- a/roles/ipmi_exporter/molecule/alternative/molecule.yml +++ b/roles/ipmi_exporter/molecule/alternative/molecule.yml @@ -1,11 +1,12 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: ipmi_exporter_binary_local_dir: "/tmp/ipmi_exporter-linux-amd64" ipmi_exporter_web_listen_address: "127.0.0.1:8080" - ipmi_exporter_tls_server_config: cert_file: /etc/ipmi_exporter/tls.cert key_file: /etc/ipmi_exporter/tls.key @@ -15,3 +16,6 @@ provisioner: randomuser: examplepassword go_arch: amd64 ipmi_exporter_version: 1.6.1 + ipmi_exporter_binary_url: "https://github.com/prometheus-community/ipmi_exporter/releases/download/v{{\ + \ ipmi_exporter_version }}/ipmi_exporter-{{ ipmi_exporter_version }}.linux-{{\ + \ go_arch }}.tar.gz" diff --git a/roles/memcached_exporter/molecule/alternative/molecule.yml b/roles/memcached_exporter/molecule/alternative/molecule.yml index db81a1f6..42130761 100644 --- a/roles/memcached_exporter/molecule/alternative/molecule.yml +++ b/roles/memcached_exporter/molecule/alternative/molecule.yml @@ -1,11 +1,12 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: memcached_exporter_binary_local_dir: "/tmp/memcached_exporter-linux-amd64" memcached_exporter_web_listen_address: "127.0.0.1:8080" - memcached_exporter_tls_server_config: cert_file: /etc/memcached_exporter/tls.cert key_file: /etc/memcached_exporter/tls.key @@ -15,3 +16,6 @@ provisioner: randomuser: examplepassword go_arch: amd64 memcached_exporter_version: 0.12.0 + memcached_exporter_binary_url: "https://github.com/prometheus/memcached_exporter/releases/download/v{{\ + \ memcached_exporter_version }}/memcached_exporter-{{ memcached_exporter_version }}.linux-{{\ + \ go_arch }}.tar.gz" diff --git a/roles/mongodb_exporter/molecule/alternative/molecule.yml b/roles/mongodb_exporter/molecule/alternative/molecule.yml index c9807730..0e14d811 100644 --- a/roles/mongodb_exporter/molecule/alternative/molecule.yml +++ b/roles/mongodb_exporter/molecule/alternative/molecule.yml @@ -1,11 +1,12 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: mongodb_exporter_binary_local_dir: "/tmp/mongodb_exporter-linux-amd64_local" mongodb_exporter_web_listen_address: "127.0.1.1:9216" - mongodb_exporter_tls_server_config: cert_file: /etc/mongodb_exporter/tls.cert key_file: /etc/mongodb_exporter/tls.key @@ -15,3 +16,5 @@ provisioner: randomuser: examplepassword go_arch: amd64 mongodb_exporter_version: 0.40.0 + mongodb_exporter_binary_url: "https://github.com/percona/mongodb_exporter/releases/download/v{{ mongodb_exporter_version }}/\ + mongodb_exporter-{{ mongodb_exporter_version }}.linux-{{ go_arch }}.tar.gz" diff --git a/roles/mysqld_exporter/molecule/alternative/molecule.yml b/roles/mysqld_exporter/molecule/alternative/molecule.yml index b5a4cec8..153959e8 100644 --- a/roles/mysqld_exporter/molecule/alternative/molecule.yml +++ b/roles/mysqld_exporter/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -11,7 +13,6 @@ provisioner: - slave_hosts mysqld_exporter_disabled_collectors: - global_variables - mysqld_exporter_tls_server_config: cert_file: /etc/mysqld_exporter/tls.cert key_file: /etc/mysqld_exporter/tls.key @@ -21,3 +22,6 @@ provisioner: randomuser: examplepassword go_arch: amd64 mysqld_exporter_version: 0.15.0 + mysqld_exporter_binary_url: "https://github.com/prometheus/mysqld_exporter/releases/download/v{{\ + \ mysqld_exporter_version }}/mysqld_exporter-{{ mysqld_exporter_version\ + \ }}.linux-{{ go_arch }}.tar.gz" diff --git a/roles/nginx_exporter/molecule/alternative/molecule.yml b/roles/nginx_exporter/molecule/alternative/molecule.yml index 4b42c183..8ae88394 100644 --- a/roles/nginx_exporter/molecule/alternative/molecule.yml +++ b/roles/nginx_exporter/molecule/alternative/molecule.yml @@ -1,11 +1,12 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: nginx_exporter_binary_local_dir: "/tmp/nginx_exporter-linux-amd64_local" nginx_exporter_web_listen_address: "127.0.0.1:9113" - nginx_exporter_tls_server_config: cert_file: /etc/nginx_exporter/tls.cert key_file: /etc/nginx_exporter/tls.key @@ -15,3 +16,5 @@ provisioner: randomuser: examplepassword go_arch: amd64 nginx_exporter_version: 1.1.0 + nginx_exporter_binary_url: "https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v{{ nginx_exporter_version }}/\ + nginx-prometheus-exporter_{{ nginx_exporter_version }}_linux_{{ go_arch }}.tar.gz" diff --git a/roles/node_exporter/molecule/alternative/molecule.yml b/roles/node_exporter/molecule/alternative/molecule.yml index a9d1c7a6..508f9af1 100644 --- a/roles/node_exporter/molecule/alternative/molecule.yml +++ b/roles/node_exporter/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -12,7 +14,6 @@ provisioner: - entropy node_exporter_disabled_collectors: - diskstats - node_exporter_tls_server_config: cert_file: /etc/node_exporter/tls.cert key_file: /etc/node_exporter/tls.key @@ -22,3 +23,6 @@ provisioner: randomuser: examplepassword go_arch: amd64 node_exporter_version: 1.5.0 + node_exporter_binary_url: "https://github.com/prometheus/node_exporter/releases/download/v{{\ + \ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-{{\ + \ go_arch }}.tar.gz" diff --git a/roles/postgres_exporter/molecule/alternative/molecule.yml b/roles/postgres_exporter/molecule/alternative/molecule.yml index 4a8d5da4..da17a594 100644 --- a/roles/postgres_exporter/molecule/alternative/molecule.yml +++ b/roles/postgres_exporter/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -11,7 +13,6 @@ provisioner: - postmaster postgres_exporter_disabled_collectors: - replication - postgres_exporter_tls_server_config: cert_file: /etc/postgres_exporter/tls.cert key_file: /etc/postgres_exporter/tls.key @@ -21,3 +22,6 @@ provisioner: randomuser: examplepassword go_arch: amd64 postgres_exporter_version: 0.15.0 + postgres_exporter_binary_url: "https://github.com/prometheus-community/postgres_exporter/releases/download/v{{\ + \ postgres_exporter_version }}/postgres_exporter-{{ postgres_exporter_version\ + \ }}.linux-{{ go_arch }}.tar.gz" diff --git a/roles/process_exporter/molecule/alternative/molecule.yml b/roles/process_exporter/molecule/alternative/molecule.yml index 8b6b51fc..4d9c97d7 100644 --- a/roles/process_exporter/molecule/alternative/molecule.yml +++ b/roles/process_exporter/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -26,3 +28,6 @@ provisioner: cmdline: - crond {% endraw %} + process_exporter_binary_url: "https://github.com/ncabatoff/process-exporter/releases/download/v{{\ + \ process_exporter_version }}/process-exporter-{{ process_exporter_version }}.linux-{{\ + \ go_arch }}.tar.gz" diff --git a/roles/prometheus/molecule/alternative/molecule.yml b/roles/prometheus/molecule/alternative/molecule.yml index e8d44cbf..76c70849 100644 --- a/roles/prometheus/molecule/alternative/molecule.yml +++ b/roles/prometheus/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -88,3 +90,5 @@ provisioner: replacement: 127.0.0.1:9115 # Blackbox exporter. prometheus_version: 2.25.2 prometheus_stop_timeout: 1min + prometheus_binary_url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version\ + \ }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz" diff --git a/roles/pushgateway/molecule/alternative/molecule.yml b/roles/pushgateway/molecule/alternative/molecule.yml index e0534421..ab4b97bb 100644 --- a/roles/pushgateway/molecule/alternative/molecule.yml +++ b/roles/pushgateway/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -16,3 +18,5 @@ provisioner: randomuser: examplepassword go_arch: amd64 pushgateway_version: 1.5.1 + pushgateway_binary_url: "https://github.com/prometheus/pushgateway/releases/download/v{{ pushgateway_version\ + \ }}/pushgateway-{{ pushgateway_version }}.linux-{{ go_arch }}.tar.gz" diff --git a/roles/redis_exporter/molecule/alternative/molecule.yml b/roles/redis_exporter/molecule/alternative/molecule.yml index b0120f9f..95916170 100644 --- a/roles/redis_exporter/molecule/alternative/molecule.yml +++ b/roles/redis_exporter/molecule/alternative/molecule.yml @@ -1,13 +1,19 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: redis_exporter_binary_local_dir: "/tmp/redis_exporter-linux-amd64" redis_exporter_web_listen_address: "127.0.0.1:8080" - - redis_exporter_tls_server_ca_cert_file: /etc/redis_exporter/tls.cert - redis_exporter_tls_server_cert_file: /etc/redis_exporter/tls.cert - redis_exporter_tls_server_key_file: /etc/redis_exporter/tls.key + redis_exporter_tls_server_config: + cert_file: /etc/redis_exporter/tls.cert + key_file: /etc/redis_exporter/tls.key + redis_exporter_tls_server_cert_file: "{{ redis_exporter_tls_server_config.cert_file }}" + redis_exporter_tls_server_key_file: "{{ redis_exporter_tls_server_config.key_file }}" go_arch: amd64 redis_exporter_version: 1.58.0 + redis_exporter_binary_url: "https://github.com/oliver006/redis_exporter/releases/download/v{{\ + \ redis_exporter_version }}/redis_exporter-v{{ redis_exporter_version }}.linux-{{\ + \ go_arch }}.tar.gz" diff --git a/roles/smartctl_exporter/molecule/alternative/molecule.yml b/roles/smartctl_exporter/molecule/alternative/molecule.yml index 38c6ec55..fa83c8f6 100644 --- a/roles/smartctl_exporter/molecule/alternative/molecule.yml +++ b/roles/smartctl_exporter/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -9,7 +11,6 @@ provisioner: smartctl_exporter_smartctl_rescan: "5m" smartctl_exporter_smartctl_device_include: "/dev/sda" smartctl_exporter_smartctl_device_exclude: "/dev/sdb" - smartctl_exporter_tls_server_config: cert_file: /etc/smartctl_exporter/tls.cert key_file: /etc/smartctl_exporter/tls.key @@ -19,3 +20,6 @@ provisioner: randomuser: examplepassword go_arch: amd64 smartctl_exporter_version: 0.11.0 + smartctl_exporter_binary_url: "https://github.com/prometheus-community/smartctl_exporter/releases/download/v{{\ + \ smartctl_exporter_version }}/smartctl_exporter-{{ smartctl_exporter_version }}.linux-{{\ + \ go_arch }}.tar.gz" diff --git a/roles/smokeping_prober/molecule/alternative/molecule.yml b/roles/smokeping_prober/molecule/alternative/molecule.yml index cc00e9e9..72671055 100644 --- a/roles/smokeping_prober/molecule/alternative/molecule.yml +++ b/roles/smokeping_prober/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -16,3 +18,7 @@ provisioner: randomuser: examplepassword go_arch: amd64 smokeping_prober_version: 0.7.0 + smokeping_prober_archive_path: /tmp + smokeping_archive_path: /tmp + smokeping_prober_binary_url: "https://github.com/superq/smokeping_prober/releases/download/v{{ smokeping_prober_version\ + \ }}/smokeping_prober-{{ smokeping_prober_version }}.linux-{{ go_arch }}.tar.gz" diff --git a/roles/systemd_exporter/molecule/alternative/molecule.yml b/roles/systemd_exporter/molecule/alternative/molecule.yml index 17c10dff..d33138d8 100644 --- a/roles/systemd_exporter/molecule/alternative/molecule.yml +++ b/roles/systemd_exporter/molecule/alternative/molecule.yml @@ -1,5 +1,7 @@ --- provisioner: + playbooks: + prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -11,3 +13,6 @@ provisioner: cert_file: /etc/systemd_exporter/tls.cert key_file: /etc/systemd_exporter/tls.key systemd_exporter_enable_file_descriptor_size: true + systemd_exporter_binary_url: "https://github.com/prometheus-community/systemd_exporter/releases/download/v{{\ + \ systemd_exporter_version }}/systemd_exporter-{{ systemd_exporter_version\ + \ }}.linux-{{ go_arch }}.tar.gz"