From b69a6f18ffd0406711146c11f3869af16e98d26d Mon Sep 17 00:00:00 2001 From: SuperQ Date: Sat, 29 Jul 2023 10:49:33 +0200 Subject: [PATCH 1/2] fix: Add test for argument_specs matching Compare contents of `meta/arguments_spec.yml` against `defaults/main.yml` on each role to make sure keys match. Signed-off-by: SuperQ --- .github/scripts/lint_arguments_spec.sh | 22 ++++++++++++++++++++++ .github/workflows/ansible-ci.yml | 9 +++++++++ 2 files changed, 31 insertions(+) create mode 100755 .github/scripts/lint_arguments_spec.sh diff --git a/.github/scripts/lint_arguments_spec.sh b/.github/scripts/lint_arguments_spec.sh new file mode 100755 index 000000000..798b83f65 --- /dev/null +++ b/.github/scripts/lint_arguments_spec.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# Description: Lint the defaults/main.yml against the meta/arguments_spec.yml + +lint_diff() { + diff -u \ + <(yq 'keys | .[]' "${role}/defaults/main.yml" | sort -u) \ + <(yq '.argument_specs.main.options | keys | .[] ' "${role}/meta/argument_specs.yml" | sort -u) + return $? +} + +error=0 + +for role in roles/* ; do + echo "Checking ${role}" + if ! lint_diff ; then + echo "ERROR: ${role}: meta/argument_specs.yml doesn't match defaults/main.yml" + error=1 + fi +done + +exit "${error}" diff --git a/.github/workflows/ansible-ci.yml b/.github/workflows/ansible-ci.yml index 14aad9126..cc72e0242 100644 --- a/.github/workflows/ansible-ci.yml +++ b/.github/workflows/ansible-ci.yml @@ -29,6 +29,15 @@ jobs: - name: Lint collection uses: ansible/ansible-lint-action@main + arguments-spec-lint: + runs-on: ubuntu-latest + container: + image: quay.io/prometheus/golang-builder:base + steps: + - uses: actions/checkout@v3 + - name: Lint arguments spec + run: ./.github/scripts/lint_arguments_spec.sh + discover-ansible-versions: runs-on: ubuntu-latest outputs: From 5c8fe6051aea97094475e92503b0326908dbf861 Mon Sep 17 00:00:00 2001 From: SuperQ Date: Sat, 29 Jul 2023 14:22:12 +0200 Subject: [PATCH 2/2] Fixup arguments_spec linting issues. Signed-off-by: SuperQ --- roles/blackbox_exporter/meta/argument_specs.yml | 6 ++++++ roles/mysqld_exporter/defaults/main.yml | 4 ++-- roles/mysqld_exporter/meta/argument_specs.yml | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/roles/blackbox_exporter/meta/argument_specs.yml b/roles/blackbox_exporter/meta/argument_specs.yml index b5c9b23d2..ab97d1bfb 100644 --- a/roles/blackbox_exporter/meta/argument_specs.yml +++ b/roles/blackbox_exporter/meta/argument_specs.yml @@ -37,3 +37,9 @@ argument_specs: blackbox_exporter_config_dir: description: "Directory where the blackbox exporter configuration file is placed" default: "/etc" + blackbox_exporter_user: + description: "The user the exporter runs as" + default: "blackbox-exp" + blackbox_exporter_group: + description: "The group the exporter runs as" + default: "blackbox-exp" diff --git a/roles/mysqld_exporter/defaults/main.yml b/roles/mysqld_exporter/defaults/main.yml index d85a41ab9..cd4637698 100644 --- a/roles/mysqld_exporter/defaults/main.yml +++ b/roles/mysqld_exporter/defaults/main.yml @@ -13,8 +13,8 @@ mysqld_exporter_username: exporter mysqld_exporter_password: secret mysqld_exporter_config_file: "mysqld_exporter.cnf" -# mysqld_exporter_host: localhost -# mysqld_exporter_port: 3306 +mysqld_exporter_host: null +mysqld_exporter_port: null mysqld_exporter_socket: "/run/mysqld/mysqld.sock" mysqld_exporter_tls_server_config: {} diff --git a/roles/mysqld_exporter/meta/argument_specs.yml b/roles/mysqld_exporter/meta/argument_specs.yml index 77abafa41..6dfac06d2 100644 --- a/roles/mysqld_exporter/meta/argument_specs.yml +++ b/roles/mysqld_exporter/meta/argument_specs.yml @@ -32,6 +32,9 @@ argument_specs: mysqld_exporter_web_telemetry_path: description: "Path under which to expose metrics" default: "/metrics" + mysqld_exporter_config_dir: + description: "The path where exporter configuration is stored" + default: "/etc/mysqld_exporter" mysqld_exporter_config_file: description: "The filename of the exporter mysql config file" default: "mysqld_exporter.cnf" @@ -42,6 +45,12 @@ argument_specs: mysqld_exporter_socket: description: "The target MySQL unix socket" default: "/run/mysqld/mysqld.sock" + mysqld_exporter_username: + description: "The username for MySQL login" + default: "exporter" + mysqld_exporter_password: + description: "The password for MySQL login" + default: "secret" mysqld_exporter_enabled_collectors: description: - "List of dicts defining additionally enabled collectors and their configuration."