Skip to content

Commit

Permalink
feat: move naive assertion to common role
Browse files Browse the repository at this point in the history
Signed-off-by: Jack <jack4zhang@gmail.com>
  • Loading branch information
zhan9san committed Oct 30, 2024
1 parent e2d8b74 commit 2ec62b3
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 209 deletions.
3 changes: 3 additions & 0 deletions roles/_common/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ argument_specs:
{{ ('python-apt' if ansible_python_version is version('3', '<') else 'python3-apt') }}
{% else %}\
{% endif %}"
_common_web_listen_address:
description: "Address on which to listen"
default: ""
selinux:
short_description: "Internal only - common selinux configuration tasks"
description: "Internal only - selinux requirements"
Expand Down
11 changes: 11 additions & 0 deletions roles/_common/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,14 @@
- "{{ ansible_parent_role_names | first | regex_replace(ansible_collection_name ~ '.', '') }}_configure"
- install
- "{{ ansible_parent_role_names | first | regex_replace(ansible_collection_name ~ '.', '') }}_install"

- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[_common_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
when: (_common_web_listen_address)
1 change: 1 addition & 0 deletions roles/_common/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _common_binary_unarchive_opts: ""
_common_tls_server_config: {}
_common_http_server_config: {}
_common_basic_auth_users: {}
_common_web_listen_address: ""
# Variables that should not be overwritten
__common_binary_basename: "{{ _common_binary_url | urlsplit('path') | basename }}"
__common_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}"
Expand Down
12 changes: 2 additions & 10 deletions roles/alertmanager/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
vars:
_common_web_listen_address: "{{ alertmanager_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
Expand All @@ -15,16 +17,6 @@
alertmanager_web_listen_address | type_debug == "list"
)
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[alertmanager_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Discover latest version
ansible.builtin.set_fact:
alertmanager_version: "{{ (lookup('url', 'https://api.github.com/repos/{{ _alertmanager_repo }}/releases/latest', headers=_github_api_headers,
Expand Down
12 changes: 2 additions & 10 deletions roles/bind_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml

- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[bind_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
vars:
_common_web_listen_address: "{{ bind_exporter_web_listen_address }}"

- name: Assert that TLS config is correct
when: bind_exporter_tls_server_config | length > 0
Expand Down
11 changes: 1 addition & 10 deletions roles/blackbox_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
tasks_from: preflight.yml
vars:
_common_dependencies: "{{ _blackbox_exporter_dependencies }}"
_common_web_listen_address: "{{ blackbox_exporter_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
Expand All @@ -17,16 +18,6 @@
blackbox_exporter_web_listen_address | type_debug == "list"
)
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[blackbox_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Discover latest version
ansible.builtin.set_fact:
blackbox_exporter_version: "{{ (lookup('url', 'https://api.github.com/repos/{{ _blackbox_exporter_repo }}/releases/latest', headers=_github_api_headers,
Expand Down
12 changes: 2 additions & 10 deletions roles/chrony_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
vars:
_common_web_listen_address: "{{ chrony_exporter_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
Expand All @@ -15,16 +17,6 @@
chrony_exporter_web_listen_address | type_debug == "list"
)
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[chrony_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Assert collectors are not both disabled and enabled at the same time
ansible.builtin.assert:
that:
Expand Down
12 changes: 2 additions & 10 deletions roles/fail2ban_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
vars:
_common_web_listen_address: "{{ fail2ban_exporter_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
that:
- >-
fail2ban_exporter_web_listen_address is string
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[fail2ban_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Discover latest version
ansible.builtin.set_fact:
fail2ban_exporter_version: "{{ (lookup('url', 'https://gitlab.com/api/v4/projects/{{ _fail2ban_exporter_repo }}/releases',
Expand Down
17 changes: 3 additions & 14 deletions roles/influxdb_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
vars:
_common_web_listen_address: "{{ influxdb_exporter_web_listen_address }}"

tags:
- influxdb_exporter
- preflight
Expand All @@ -17,20 +20,6 @@
- preflight
- influxdb_exporter_preflight

- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[influxdb_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
tags:
- influxdb_exporter
- preflight
- influxdb_exporter_preflight

- 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,
Expand Down
11 changes: 1 addition & 10 deletions roles/ipmi_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,14 @@
tasks_from: preflight.yml
vars:
_common_dependencies: "{{ _ipmi_exporter_dependencies }}"
_common_web_listen_address: "{{ ipmi_exporter_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
that:
- >-
ipmi_exporter_web_listen_address is string
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[ipmi_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Assert that TLS config is correct
when: ipmi_exporter_tls_server_config | length > 0
block:
Expand Down
12 changes: 2 additions & 10 deletions roles/memcached_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
vars:
_common_web_listen_address: "{{ memcached_exporter_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
that:
- >-
memcached_exporter_web_listen_address is string
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[memcached_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Assert that TLS config is correct
when: memcached_exporter_tls_server_config | length > 0
block:
Expand Down
12 changes: 2 additions & 10 deletions roles/mongodb_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
vars:
_common_web_listen_address: "{{ mongodb_exporter_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
that:
- >-
mongodb_exporter_web_listen_address is string
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[mongodb_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Assert that TLS config is correct
when: mongodb_exporter_tls_server_config | length > 0
block:
Expand Down
12 changes: 2 additions & 10 deletions roles/mysqld_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
vars:
_common_web_listen_address: "{{ mysqld_exporter_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
Expand All @@ -15,16 +17,6 @@
mysqld_exporter_web_listen_address | type_debug == "list"
)
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[mysqld_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Assert collectors are not both disabled and enabled at the same time
ansible.builtin.assert:
that:
Expand Down
12 changes: 2 additions & 10 deletions roles/nginx_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
vars:
_common_web_listen_address: "{{ nginx_exporter_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
that:
- >-
nginx_exporter_web_listen_address is string
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[nginx_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Assert that TLS config is correct
when: nginx_exporter_tls_server_config | length > 0
block:
Expand Down
12 changes: 2 additions & 10 deletions roles/node_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
vars:
_common_web_listen_address: "{{ node_exporter_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
Expand All @@ -15,16 +17,6 @@
node_exporter_web_listen_address | type_debug == "list"
)
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[node_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Assert collectors are not both disabled and enabled at the same time
ansible.builtin.assert:
that:
Expand Down
12 changes: 2 additions & 10 deletions roles/postgres_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml
vars:
_common_web_listen_address: "{{ postgres_exporter_web_listen_address }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
Expand All @@ -15,16 +17,6 @@
postgres_exporter_web_listen_address | type_debug == "list"
)
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- >-
[postgres_exporter_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Assert collectors are not both disabled and enabled at the same time
ansible.builtin.assert:
that:
Expand Down
7 changes: 2 additions & 5 deletions roles/process_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
ansible.builtin.include_role:
name: prometheus.prometheus._common
tasks_from: preflight.yml

- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- "':' in process_exporter_web_listen_address"
vars:
_common_web_listen_address: "{{ process_exporter_web_listen_address }}"

- name: Discover latest version
ansible.builtin.set_fact:
Expand Down
Loading

0 comments on commit 2ec62b3

Please sign in to comment.