test: unified prepare playbook for alternative molecule scenarios

Signed-off-by: gardar <gardar@users.noreply.github.com>
This commit is contained in:
gardar 2024-09-18 03:49:54 +00:00
parent c59483a92f
commit b471a1f4a4
No known key found for this signature in database
GPG key ID: 00872BAF59D98753
20 changed files with 196 additions and 13 deletions

View file

@ -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 }}"

View file

@ -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"

View file

@ -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"

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"